2

我正在尝试通过他们的 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时,我看到了那里的服务用户,并且在“权限”列中它具有“完整”。

谁能帮我理解为什么我在运行代码时会出现以下错误?

{
  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只是将我链接到搜索控制台用户页面......(再次)表示服务用户具有完全权限。

4

0 回答 0