首页 > 解决方案 > 使用 Google Indexing API 索引 URL

问题描述

我正在使用本指南创建一个 Python 程序来索引我的网页中的 URL。我已经测试了指南提供的 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 = "service_account_file.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.generawork.tk/planillas-de-luz-ecuador-2020/",
  \"type\": \"URL_UPDATED\"
}"""

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

输出是这样的:

b'{\n  "urlNotificationMetadata": {\n    "url": "https://www.generawork.tk/planillas-de-luz-ecuador-2020/",\n    "latestUpdate": {\n      "url": "https://www.generawork.tk/planillas-de-luz-ecuador-2020/",\n      "type": "URL_UPDATED",\n      "notifyTime": "2020-09-03T19:49:05.614934282Z"\n    }\n  }\n}\n'

我一直在等待URL被索引,但什么也没发生,这让我认为使用这个API,URL只能更新或删除

第一次使用此 API 是否可以将 URL 编入索引?然后。怎么做?

标签: pythonpython-3.xpython-2.7google-chromegoogle-indexing-api

解决方案


推荐阅读