Thursday, July 4, 2024

How to Index New Blog Post in Google Quickly | Instant Indexing Set Up on Blogger

 


Please go through this Video to setup a Project, API Key, Generate JSON file, Add generated email -> https://www.youtube.com/watch?v=34klagkAw5I

Link to Google cloud - https://console.cloud.google.com/ 

Link to Google Indexing API - https://colab.research.google.com/drive/1fsrcd91tBpVwhRCBsZfmcvR1FobnJVqU

Login to Google Indexing API | Blogger | WordPress using

 https://colab.research.google.com/drive/1fsrcd91tBpVwhRCBsZfmcvR1FobnJVqU#scrollTo=jMkignjy9Rpb

Once done 

Upload JSON File Here! -> upload the JSON File and click on the Run Cell (refer to the above youtube video on how to generate the JSON File)



Import Necessary Libraries -> Click on Run Cell



Go to -> "Provide Site URL & Update Request Type" section



Enter the 

siteURL:

requestType: URL_UPDATED


Click on run Cell

If you get "NameError: name 'http' is not defined"

Then

Hypothesis

The error message "NameError: name 'http' is not defined" means that the variable http is being used in the code but hasn't been assigned a value within the current scope. Looking at the traceback, the error occurs in the second code block where you are trying to make a request using http.request(). It is likely that the variable http was defined in the first code block but is not accessible in the second because they are in separate cells. In Python, variables defined in one cell are not automatically available in another.


Suggested Changes

To fix this, you need to make sure that the http variable is defined in the second code block as well. You can achieve this by either running both code blocks in the same cell or by moving the code that defines http to a separate Python file and importing it into both notebooks.


Here's how you can modify your code: 

Click on "Show Code" button 



And add the below Code

#@title **Import Necessary Libraries**

#@markdown Using this, we will define the scopes and endpoints of or API and authorize the JSON Key.

for key, value in uploaded_key.items():

    json_key_name = key

from oauth2client.service_account import ServiceAccountCredentials

import httplib2


SCOPES = ["https://www.googleapis.com/auth/indexing"]

ENDPOINT = "https://indexing.googleapis.com/v3/urlNotifications:publish"

print('*'*50);print("Scopes & Endpoint Configured...");print('*'*50);print("Adding Key...");print('*'*50);

# service_account_file.json is the private key that you created for your service account.

JSON_KEY_FILE = json_key_name

print("Key Added Successfully!");print('*'*50);

credentials = ServiceAccountCredentials.from_json_keyfile_name(JSON_KEY_FILE, scopes=SCOPES)

http = credentials.authorize(httplib2.Http()) # Define http here so it's available

print("Credentials Successfully Authorized!");print('*'*50);


#@title **Provide Site URL & Update Request Type**

#@markdown Site URL will the exact URL you want to update or delete from the Google Search Index. **Also, please make a note that you have to provide URL only for the ownership verfied website. For any other URLs, it will not work.**

siteURL = "https://simplilearnat.blogspot.com/2024/07/ifbagro-rally-more-than-20-and-stocks.html" #@param {type:"string"}

requestType = "URL_UPDATED" #@param ["URL_UPDATED", "URL_DELETED"]

content = str({'url':siteURL,'type':requestType})

print("RESULT:");print('*'*50);print("URL and Update Request Type Configured!");print('*'*50);


response, content = http.request(ENDPOINT, method="POST", body=content) # Now http is defined

output = response['status']


if output == '200':

  print("Successfully Done!");print('*'*50);


else:

  print("Error Code: {}".format(output));print('*'*50);

  print("Visit Here For More: https://developers.google.com/search/apis/indexing-api/v3/core-errors#api-errors");

  print('*'*50);

  

And then enter


siteURL: https://simplilearnat.blogspot.com/2024/07/ifbagro-rally-more-than-20-and-stocks.html

requestType: URL_UPDATED


Click on run Cell



You will see the following output


**************************************************

Scopes & Endpoint Configured...

**************************************************

Adding Key...

**************************************************

Key Added Successfully!

**************************************************

Credentials Successfully Authorized!

**************************************************

RESULT:

**************************************************

URL and Update Request Type Configured!

**************************************************

Successfully Done!

**************************************************





Wait for few Hours and you should see your page is being indexed