【发布时间】:2020-11-17 09:14:21
【问题描述】:
我正在尝试使用 Vuejs 和 Javascript 从我的 Web 应用程序将文件上传到 Google Drive,但是当我发送请求时,它会标记该错误。 我检查了变量code的值是null,甚至变量window.location.search也是一个空字符串,但我没有知道代码变量在请求中应该有什么值。
这是代码部分:
const urlParams = new URLSearchParams(window.location.search);
console.log ("Value of window.location.search", window.location.search);
const code = urlParams.get('code');
console.log ("Valor de code", code);
const redirect_uri = "http://localhost:3000/formacionProf"
const client_secret = clientSecret;
const scope = "https://www.googleapis.com/auth/drive";
let access_token= "";
let client_id = clientID;
$.ajax({
type: 'POST',
url: "https://www.googleapis.com/oauth2/v4/token",
data: {
code: code,
redirect_uri: redirect_uri,
client_secret: client_secret,
client_id: client_id,
scope: scope,
grant_type: "authorization_code"
},
dataType: "json",
success: function(resultData) {
localStorage.setItem("accessToken",resultData.access_token);
localStorage.setItem("refreshToken",resultData.refreshToken);
localStorage.setItem("expires_in",resultData.expires_in);
window.history.pushState({}, document.title, "/formacionProf");
},
error: function (error) {
console.log(error);
}
});
感谢您的宝贵时间。
【问题讨论】:
-
您不使用该库的任何原因? developers.google.com/drive/api/v3/quickstart/js
标签: javascript ajax google-api