Index URLs using Google Indexing API

430 views Asked by At

I´m using this guide to create a Python program to index URLs from my web pages. I have tested the Python example which the guide provides

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)

The output is this:

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'

I have waited for the URL to be indexed, but nothing has happened, this leads me to think that using this API, URLs can only be updated or deleted

Can a URL be indexed for the first time using this API? Then. How to do it?

0

There are 0 answers