gpt4 book ai didi

python - 使用 Python 的 Google 索引 API

转载 作者:行者123 更新时间:2023-12-04 16:33:27 27 4
gpt4 key购买 nike

这是我使用 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

最佳答案

它对我有用

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.
# This example shows a simple update request.
# Other types of requests are described in the next step.

content = """{
"url": "https://mysmartpros.com/tutor-tuition-online-jobs/economics",
"type": "URL_UPDATED"
}"""

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

print(response)
print(content)```

{'content-type': 'application/json; charset=UTF-8', 'vary': 'Origin, X-Origin, Referer', 'date': 'Mon, 25 Jan 2021 23:48:59 GMT', 'server': 'ESF', 'cache-control': 'private', 'x-xss-protection': '0', 'x-frame-options': 'SAMEORIGIN', 'x-content-type-options': 'nosniff', 'transfer-encoding': 'chunked', 'status': '200', 'content-length': '299', '-content-encoding': 'gzip'}


b'{\n "urlNotificationMetadata": {\n "url": "https://mysmartpros.com/tutor-tuition-online-jobs/economics",\n "latestUpdate": {\n "url": "https://mysmartpros.com/tutor-tuition-online-jobs/economics",\n "type": "URL_UPDATED",\n "notifyTime": "2021-01-25T23:48:59.783031464Z"\n }\n }\n}\n'

关于python - 使用 Python 的 Google 索引 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65889022/

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