Google Search Console API - 全域委派 - 未返回任何结果

Google Search Console API - Domain Wide Delegation - Returning no results

我为我们的 Google 应用程序域设置(至少尝试过)域范围的委托,以便与 python 脚本集成。特别是,我目前正在尝试与 Search Console 进行交互 API。

这是我所做的:

  1. 设置服务帐户
  2. 启用全域委派
  3. 已将 https://www.googleapis.com/auth/webmasters.readonly 添加到授权 API 客户列表的 Google 管理控制台。
  4. 根据 Google
  5. 提供的脚本设置一个简单的脚本

这是我的 test.py 脚本:

#!/usr/bin/python

from oauth2client.service_account import ServiceAccountCredentials
from httplib2 import Http
from apiclient.discovery import build


scopes = [
        'https://www.googleapis.com/auth/webmasters.readonly',
    ]

credentials = ServiceAccountCredentials.from_json_keyfile_name('/path/to/my/key.json', scopes)
delegated_credentials = credentials.create_delegated('me@mydomain.com')

http_auth = credentials.authorize(Http())

webmasters_service = build('webmasters', 'v3', http=http_auth)

site_list = webmasters_service.sites().list().execute()

print site_list

结果:

{}

无赖。

我知道这是不正确的,因为当我使用 API Explorer 并授权 me@mydomain.com 时,我会在 Search Console 中看到我的网站的完整列表。东西坏了,我不确定问题出在哪里。

对我在这个过程中遗漏的步骤有什么想法吗?一切似乎都经过验证。我没有得到 403

挠头

所以我不是 100% 确定我做了什么,或者我是如何修复它的。

我在管理控制台 API 客户端访问实用程序中使用具有和不具有尾随 / 的权限。最后,我将范围从 https://www.googleapis.com/auth/webmasters.readonly 更改为 https://www.googleapis.com/auth/webmasters 并且成功了!

我还没有回去玩只读范围,部分原因是我确实希望我的程序具有写访问权限。我只是出于测试目的使用只读。