My current issue involves uploading files to Google Drive from my Vuejs and JavaScript web application. The request I send is returning an error. Upon checking, I noticed that the variable code is null, and even the variable window.location.search is empty. However, I am unsure of what value the code variable should contain in the request.
Below is the relevant section of code:
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);
}
});
Thank you for your assistance.