gpt4 book ai didi

python - Google Search Console API - 域范围委派 - 不返回任何结果

转载 作者:太空宇宙 更新时间:2023-11-03 16:54:08 25 4
gpt4 key购买 nike

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

这是我所做的:

  1. 设置服务帐户
  2. 启用域范围委托(delegate)
  3. 在 Google 管理控制台中添加了 https://www.googleapis.com/auth/webmasters.readonly 授权 API 客户端列表。
  4. 根据 Google 提供的脚本设置一个简单的脚本

这是我的 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它成功了!

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

关于python - Google Search Console API - 域范围委派 - 不返回任何结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35597916/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com