gpt4 book ai didi

python - OAuth 2.0 服务器到服务器凭据授权失败(Search Console - 网站管理员工具)

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

我正在尝试将 OAuth 2.0 用于 google 网站管理员工具(搜索控制台)的服务器到服务器应用程序,因此我按照说明进行操作 here .

此应用不在 Google App EngineGoogle Compute Engine

创建了服务帐户并启用了域范围委派。下载 .json 文件并将其存储到脚本的根目录。

示例:

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

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

credentials = ServiceAccountCredentials.from_json_keyfile_name(
'keyfile.json', scopes=scopes)

http_auth = credentials.authorize(Http())

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

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

但是我得到了

{} 空数据集。即使我更改了 keyfile.json 中的电子邮件地址。这告诉我该文件没有以某种方式被使用。因此,尝试获取帐户中的网站列表结果为空。

如果我这样做

site_list = webmasters_service.sitemaps().list(siteUrl="www.example.com").execute()

我得到:

googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/webmasters/v3/sites/www.example.com/sitemaps?alt=json returned "User does not have sufficient permission for site 'http://www.example.com/'. See also: https://support.google.com/webmasters/answer/2451999.">

这再次告诉我,该帐户无权获取给定 URL 的站点地图,因为它没有适当的权限。

此帐户是所有者帐户,并且服务帐户具有所有者权限。

有什么想法吗?

谢谢

最佳答案

我不想回答我自己的问题,但这是我如何让它发挥作用的;

所以底线是,在

...教程中有人忘记提及如何将新生成的电子邮件地址添加到应用程序的权限部分...

关于python - OAuth 2.0 服务器到服务器凭据授权失败(Search Console - 网站管理员工具),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36582143/

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