使用 Python 的 Google Indexing API 3 - URL_UPDATED 给出 403 错误

问题描述

我正在试用 Google 的索引 API。

使用以下代码请求内容索引:

from oauth2client.service_account import ServiceAccountCredentials
import httplib2

ScopES = [ "https://www.googleapis.com/auth/indexing" ]
ENDPOINT = "https://indexing.googleapis.com/v3/urlNotifications:publish"

# JSON Key File Location
JSON_KEY_FILE = "service_account_file.json"

credentials = ServiceAccountCredentials.from_json_keyfile_name(JSON_KEY_FILE,scopes=ScopES)

http = credentials.authorize(httplib2.Http())

content = """{
  "url": "https://digisapient.com/blog/website-international-SEO-implementation/","type": "URL_UPDATED"
}"""

response,content = http.request(ENDPOINT,method="POST",body=content)
print(response.status)
print(content)

输出

403
b'{\n  "error": {\n    "code": 403,\n    "message": "Permission denied. Failed to verify the URL ownership.",\n    "status": "PERMISSION_DENIED"\n  }\n}\n'

在 Search Console 中交叉检查用户权限。用户拥有完全权限。

服务电子邮件正确,已在开发者控制台中验证。

请指教。

解决方法

截至日期(21 年 2 月 3 日)来自 Google Search Console 的新所有者无法添加到任何经过验证的资源中。但是我们可以使用 old Google Search Console 添加新的所有者。

您可以在此处选择您的财产并添加新所有者。

enter image description here

大功告成!

快乐编码:)