Google has an “Instant Indexing API” for submitting new URLs and page updates. Officially, it only supports pages with JobPosting
and BroadcastEvent
(when embedded in VideoObject
) schema markup. However, based on my personal testing, it seems to work for normal pages as well.
For the past week, I’ve been using the Python script below to submit new posts to Google, and they all ranked much faster than usual. I’m not sure if this is safe to do because JobPosting
and BroadcastEvent
are the only two schema types that are officially supported. So, if you use this Python script to submit URLs and get penalized by Google, don’t blame me.
By the way, you’ll need to create a service account and generate a JSON key file before you can use this Python script.
from oauth2client.service_account import ServiceAccountCredentials
import httplib2
import urllib
import json
authentication_scopes = [ "https://www.googleapis.com/auth/indexing" ]
publish_endpoint = "https://indexing.googleapis.com/v3/urlNotifications:publish"
metadata_endpoint = "https://indexing.googleapis.com/v3/urlNotifications/metadata"
json_key_file = "/Users/brianli/Desktop/gsc-instant-index/key.json"
credentials = ServiceAccountCredentials.from_json_keyfile_name(json_key_file, scopes=authentication_scopes)
http = credentials.authorize(httplib2.Http())
index_url = input("What URL would you like to index? ")
payload = {
"url": index_url,
"type": "URL_UPDATED"
}
response, content = http.request(publish_endpoint, method="POST", body=json.dumps(payload))
if response.status == 200:
print(f'The submission was successful. Google reported a {response.status} response code.')
else:
print(f'The submission was not successful. Google reported a {response.status} response code, instead of 200.')
The script returns a 200 response code following a successful submission. If it gives you another response code (e.g. 3xx or 4xx), feel free to debug further by printing the content body of the HTTP response. Have fun!