我已经创建了一个域名代理服务帐户
const jwt = require("jsonwebtoken");
const sa = require("./credentials-ads.json");
const authUrl = "https://www.googleapis.com/oauth2/v4/token";
const scope = "https://www.googleapis.com/auth/adwords";
const getSignedJwt = () => {
const token = {
iss: sa.client_email,
iat: parseInt(Date.now() / 1000),
exp: parseInt(Date.now() / 1000) + 60 * 60, // 60 minutes
aud: authUrl,
scope,
};
return jwt.sign(token, sa.private_key, { algorithm: "RS256" });
};
const signedJwt = getSignedJwt();
console.log(signedJwt);
const google_token = await axios.post(
'https://oauth2.googleapis.com/token',
'grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion='+signedJwt,
{
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}
);
res.send(google_token.data);
})
上面给出access_token作为响应,但它返回如下:
{"access_token":"abcdefghijklmnopqurstuvwxyz1234567890qwertyuiopasdfghjklzxcvbnmfasdfasdfasdf........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................","expires_in":3599,"token_type":"Bearer"}
这个访问令牌不能用于任何API调用
我正在尝试使用Nodejs中的HTTP/HTTPS请求
期望收到一个可用的访问令牌,但收到一个错误的令牌.............
对于域范围委托,您必须提供要委托的主题。此值是您希望服务帐户模拟的域上用户的电子邮件地址。
您可能缺少子文件。
附加到访问令牌的多个点不会使其对Google api和服务无效。谷歌正在测试更大的代币大小。忽略点的存在,因为点是填充的。这允许Google检测截断令牌大小的应用程序。
查看更多信息:
Google云平台客户OAuth 2.0访问令牌大小