我正在尝试在node.js托管的网络应用上生成AdSense报告。 由于这是服务器到服务器的通信,因此我需要使用服务帐户。 我遵循了this指南,但是我总是遇到错误:
{
domain: "global"
message: "User does not have an AdSense account."
reason: "noAdSenseAccount"
}
还尝试了this JSON Web Tokens Guide,但上面也出现了错误。
我得到了什么:
screenshot
注意:其状态停留在“待处理”状态。
这是我尝试使用以下代码连接和检索数据的代码:
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);
});
我的问题是:
1.为什么它停留在“待定”状态?
2.是否可以使用服务帐户凭据来访问API?
3.如果可以,我可以通过哪种方式实现它?