'nom googleapi get access token in node js

I want to consume google adsense api using a js script. I don't have a running server and I just want to fetch some data using an access token.

From the documentation I saw that I have to use the consent screen in order to get the authorization code in order to get the tokens.

Is there a way to do everything programmatically? without any redirects and consent screens.

const { clientId, clientSecret } = this.query;

const oauth2Client = new google.auth.OAuth2(clientId, clientSecret, ''); // without redirect uri

const scope = ['https://www.googleapis.com/auth/adsense', 'https://www.googleapis.com/auth/adsense.readonly'];

const url = oauth2Client.generateAuthUrl({
     scope,
});

const { tokens } = await oauth2Client.getToken('code'); // how to get the code without using the consent screen



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source