我正在尝试 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 中交叉检查用户权限。用户拥有完全权限。
服务电子邮件正确,已在开发者控制台中验证。
请指教。