Last active
July 30, 2020 09:15
-
-
Save MS-Jahan/bb4e2478022d379babf6acbf784deece to your computer and use it in GitHub Desktop.
Google Index Api Simple Usage with Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 = "My-Project-2734ab3478ab.json" #You Json File | |
| 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. | |
| #Here is all the lists for indexing | |
| with open('list.txt') as my_file: | |
| arr = my_file.readlines() | |
| for url in arr: | |
| content = '{\"url\": \"' + url + '\", \"type\": \"URL_UPDATED\"}' | |
| response, content = http.request(ENDPOINT, method="POST", body=content) | |
| print(response) | |
| print("\n\n") | |
| print(content) | |
| with open("result.txt", "a") as myfile: | |
| myfile.write(str(response) + "\n\n" + str(content)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment