I'm trying to generate AdSense reports on web app hosted on node.js. Since it's a server-to-server communication i need to use service account. I followed this guide, but i always getting error:
{
domain: "global"
message: "User does not have an AdSense account."
reason: "noAdSenseAccount"
}
also tried this JSON Web Tokens Guide but also getting error above.
What i got:
screenshot
NOTE: its status stuck on "pending".
Here is the code i'm trying to connect and retrieve data with:
const googleAuth = require('google-auth-library');
const GOOGLE_KEYS = require(path.join(__dirname, '/credentials/jwt.keys.json'));
this.jwtClient = new googleAuth.JWT(
GOOGLE_KEYS.client_email,
null,
GOOGLE_KEYS.private_key,
['https://www.googleapis.com/auth/adsense'],
);
this.jwtClient.authorize(async (err: any, tokens: any) => {
if (err) throw new Error(err);
this.jwtClient.setCredentials(tokens);
const url = `https://www.googleapis.com/adsense/v1.4/accounts`;
const listData = await this.jwtClient.request({url})
.catch((err: any) => {
console.log(err, 'error');
res.status(500).json(err)
});
res.status(200).json(data);
});
My questions is:
1. Why is it stuck on "pending" status?
2. Is there a way to acceess API using service account credentials?
3. If yes which way i can achieve it?
The AdSense API doesn't support Service Accounts[1], so you'll need to make OAuth credentials using the Web App flow[2].