【发布时间】:2022-03-21 01:57:04
【问题描述】:
我正在尝试通过他们的 Node 包使用 Google 的 Search Console API,我的代码如下所示:
const auth = new GoogleAuth({
scopes: 'https://www.googleapis.com/auth/webmasters.readonly',
});
const webmasters = google.webmasters('v3');
const params = {
auth,
siteUrl: 'example.com',
resource: {
startDate: '2015-08-25',
endDate: '2015-08-25',
dimensions: ['query', 'page'],
rowLimit: 10,
},
aggregationType: 'byPage',
};
const res = await webmasters.searchanalytics.query(params);
console.log(res.data);
...除了在我的版本中 example.com 已替换为我的实际域。
我在命令行调用它:
GOOGLE_APPLICATION_CREDENTIALS="/path/to/service_key.json" node index.js
我创建了一个服务帐户,服务密钥 JSON 文件来自该帐户。该服务帐户有权访问我的 Search Console 帐户。当我查看https://search.google.com/search-console/users 时,我看到了那里的服务用户,并且在 Permission 列中它有“Full”。
谁能帮我理解为什么我在运行代码时会出现以下错误?
{
message: "User does not have sufficient permission for site 'http://example.com'. See also: https://support.google.com/webmasters/answer/2451999.",
domain: 'global',
reason: 'forbidden'
}
提到的 URL https://support.google.com/webmasters/answer/2451999 只是将我链接到搜索控制台用户页面...(再次)表明服务用户拥有完全权限。
【问题讨论】:
-
你找到解决方案了吗@machineghost?如果有请分享
标签: google-api google-auth-library google-auth-library-nodejs