如何解决使用 Python 的 Google 索引 API
这是我使用 python 请求谷歌索引的代码片段。
from oauth2client.service_account import ServiceAccountCredentials
import httplib2
SCOPES = [ "https://www.googleapis.com/auth/indexing" ]
ENDPOINT = "https://indexing.googleapis.com/v3/urlNotifications:publish"
# service_account_file.json is the private key that you created for your service account.
JSON_KEY_FILE = "myJSON.json"
credentials = ServiceAccountCredentials.from_json_keyfile_name(JSON_KEY_FILE,scopes=SCOPES)
http = credentials.authorize(httplib2.Http())
# Define contents here as a JSON string
content = """
{
"url": "https://locksro.weebly.com/","type": "URL_UPDATED"
}"""
#send the request
response,content = http.request(ENDPOINT,method="POST",body=content)
print(response.status)
为确保链接已编入索引,我通过在 google 中搜索 {site:locksro.weebly.com} 来检查它,但没有结果。 我无法弄清楚问题,因为 response.status 是 200
解决方法
对我有用
SpanId
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。