OAuth 2.0服务器到服务器凭据授权失败(搜索控制台 - 网站管理员工具)

时间:2016-04-12 19:16:40

标签: python google-webmaster-tools google-api-python-client google-api-webmasters

我正在尝试将OAuth 2.0用于Google网站管理员工具(Search Console)的服务器到服务器应用程序,因此我按照here的说明进行操作。

此应用程序不在PBSZ 0PROT P

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

样品:

Google 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."> 拥有所有者权限。

任何想法?

谢谢

1 个答案:

答案 0 :(得分:1)

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

所以底线是

...有些人忘记提及将新生成的电子邮件地址添加到应用程序的许可部分......