【问题标题】:Google Search Console API: How do I Solve "User does not have sufficient permission for site"? (When User Has Permissions)Google Search Console API:如何解决“用户没有足够的站点权限”? (当用户有权限时)
【发布时间】: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


【解决方案1】:

在谷歌论坛和其他互联网上扎根之后,我弄清楚了为什么会发生这种情况。

  1. 需要从 Google Cloud:https://console.cloud.google.com/apis/credentials 复制服务帐户电子邮件,格式很奇怪(例如:whiskey-tango-foxtrot@certain-something-0123456.iam.gserviceaccount.com)到 Search Console https://search.google.com/u/1/search-console/users,作为“完整站点”用户。

  2. 确保您已通过您的 API 或使用此工具添加该网站(如在 Search Console 上):https://developers.google.com/webmaster-tools/v1/sites/add

  3. 然后,当您执行“list_sites”请求时,您的站点应该被列出并且permission_level 是“siteFullUser”(根据步骤 1)

  4. 当您add_site 或执行query API 请求时,请确保根据上述步骤设置siteUrl,例如:http://www.example.com/(对于 URL 前缀属性)或sc-domain:example.com(对于域属性) ) 快乐编码

【讨论】:

    猜你喜欢
    • 2015-12-14
    • 2014-01-24
    • 1970-01-01
    • 1970-01-01
    • 2022-01-14
    • 1970-01-01
    • 2021-07-10
    • 1970-01-01
    • 2020-06-08
    相关资源
    最近更新 更多