I have a web application with React and Node.js and I am trying to connect to the Google Search Console API.
It requires authorisation so on the front end I am connecting to the correct account and scope and I am getting the OAuth2 authorizationCode
it look something like this:
4/0AX4XfWg2MKbTfn41rBjuv1wn4u5VF4G1m5p8q6-_Px-FL991ccJsn-qn6xdUbJqfM73TEw
I am then sending it to the back end but the OAuth2
returns 400
Here is what I got:
const { google } = require('googleapis');
export default async () => {
const oauth2Client = new google.auth.OAuth2(
YOUR_CLIENT_ID,
YOUR_CLIENT_SECRET,
YOUR_REDIRECT_URL
);
google.options({
auth: oauth2Client
});
// It throws 400 on this line
const { tokens } = await oauth2Client.getToken(authorizationCode);
oauth2Client.setCredentials(tokens);
const { data } = await google.webmasters.sites.list({});
console.log(data);
}
But I get 400 Bad Request