通过Web Search Indexing API实现谷歌推送网站url

 3个月前     49  

文章目录

申请免费Web Search Indexing API

  • 启用Web Search Indexing API, 点击启用API
通过Web Search Indexing API实现谷歌推送网站url

 

通过Web Search Indexing API实现谷歌推送网站url

 

通过Web Search Indexing API实现谷歌推送网站url

 

通过Web Search Indexing API实现谷歌推送网站url

 

通过Web Search Indexing API实现谷歌推送网站url

 

  • 创建json密钥文件
通过Web Search Indexing API实现谷歌推送网站url 通过Web Search Indexing API实现谷歌推送网站url 通过Web Search Indexing API实现谷歌推送网站url

下载这个json密钥文件,后面api调用要用到。

  • 将服务帐号添加到Google Search Console资源的所有者,点击进去
通过Web Search Indexing API实现谷歌推送网站url 通过Web Search Indexing API实现谷歌推送网站url

通过python API接口提交url

  • python api 网站url提交脚本例子(python3)
  • 需要安装pip3.6 install oauth2client
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 = "xxxx.json"  #你的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://www.vpsxr.com\", #每次只能一条url,可以循环提交
  \"type\": \"URL_UPDATED\"
}"""

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

 

  • 执行测试返回
python3 t.py 
{'content-type': 'application/json; charset=UTF-8', 'vary': 'Origin, X-Origin, Referer', 'date': 'Thu, 16 Nov 2023 04:11:41 GMT', 'server': 'ESF', 'cache-control': 'private', 'x-xss-protection': '0', 'x-frame-options': 'SAMEORIGIN', 'x-content-type-options': 'nosniff', 'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000', 'transfer-encoding': 'chunked', 'status': '200', 'content-length': '223', '-content-encoding': 'gzip'}
b'{\n  "urlNotificationMetadata": {\n    "url": "https://www.vpsxr.com",\n    "latestUpdate": {\n      "url": "https://www.vpsxr.com",\n      "type": "URL_UPDATED",\n      "notifyTime": "2023-11-16T04:11:40.802523428Z"\n    }\n  }\n}\n'

 

 

查看Web Search Indexing API配额

点击查看

通过Web Search Indexing API实现谷歌推送网站url

每天200条api调用限制。

版权声明:VPS推荐 发表于 3个月前,共 1623 字。提醒:请注意文章发布时间,如果太久了,相关活动可能失去时效性,请谅解!
转载请注明:通过Web Search Indexing API实现谷歌推送网站url | VPS XR
京东云-国内服务器 华为云-国内服务器

暂无评论

暂无评论...