Google indexing api python

alucard001 / GoogleIndexing.py

This file contains 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
import json
import pandas as pd
# https://developers.google.com/search/apis/indexing-api/v3/prereqs#header_2
JSON_KEY_FILE = «json_key_file_downloaded_after_creating_your_google_service_account_see_above_details_on_how_to_do.json»
SCOPES = [ «https://www.googleapis.com/auth/indexing» ]
credentials = ServiceAccountCredentials . from_json_keyfile_name ( JSON_KEY_FILE , scopes = SCOPES )
http = credentials . authorize ( httplib2 . Http ())
def indexURL ( urls , http ):
# print(type(url)); print(«URL: <>«.format(url));return;
ENDPOINT = «https://indexing.googleapis.com/v3/urlNotifications:publish»
for u in urls :
# print(«U: <> type: <>«.format(u, type(u)))
content = <>
content [ ‘url’ ] = u . strip ()
content [ ‘type’ ] = «URL_UPDATED»
json_ctn = json . dumps ( content )
# print(json_ctn);return
response , content = http . request ( ENDPOINT , method = «POST» , body = json_ctn )
result = json . loads ( content . decode ())
# For debug purpose only
if ( «error» in result ):
print ( «Error(<> — <>): <>» . format ( result [ «error» ][ «code» ], result [ «error» ][ «status» ], result [ «error» ][ «message» ]))
else :
print ( «urlNotificationMetadata.url: <>» . format ( result [ «urlNotificationMetadata» ][ «url» ]))
print ( «urlNotificationMetadata.latestUpdate.url: <>» . format ( result [ «urlNotificationMetadata» ][ «latestUpdate» ][ «url» ]))
print ( «urlNotificationMetadata.latestUpdate.type: <>» . format ( result [ «urlNotificationMetadata» ][ «latestUpdate» ][ «type» ]))
print ( «urlNotificationMetadata.latestUpdate.notifyTime: <>» . format ( result [ «urlNotificationMetadata» ][ «latestUpdate» ][ «notifyTime» ]))
«»»
data.csv has 2 columns: URL and date.
I just need the URL column.
«»»
csv = pd . read_csv ( «my_data.csv» )
csv [[ «URL» ]]. apply ( lambda x : indexURL ( x , http ))

Источник

How to use Google Indexing API with Python? on Windows

Site Logo

Google APIs are a collection of application programming interfaces (APIs) created by Google that allows users to communicate with Google Services.

APIs follow particular rules and processes to achieve that requests and responses are clearly communicated.

In this tutorial, we will try to teach how to index your web pages with the help of Google Indexing API with Python on Windows 10.

Step 1: How to explore and install Google Indexing API.

Step 2: How to connect Google Indexing API to Google Search Console.

Step 3: How to use Google Indexing API with python.

Step 1: How to explore Google Indexing API.

Visit and signup google developers console.

Then you got such a screen

Then create a new project for installing a Google Indexing API.

After the creation of the project, you got some notifications to «select project» and you can do this as per instruction.

After completing these steps you got a google developers console dashboard screen. Then select the hamburger menu on the left side of the screen and hit the click on Apis and services option > library

After this, you got this screen

Then search «google indexing API» and visit indexing API.

Then click the enable button to install this API to google developers console.

Step 2: How to associate Google Indexing API to Google Search Console.

After installation of API to google cloud console. Then again click the hamburger menu to get IAM and admin option> Service account

Читайте также:  Компьютерная графика на питоне

Create the service account by following this:

1. Fill up Service account details like a service account name.

Insert account name and username as per your choice. Then hit create and continue button.

*This service account name will be auto-filled to the service account id.

2. Give permission to this service account

Please always select the role of owner.

Then after clicking the done button and finalising these steps.

Now you can operate the Service accounts for project «XYZ» with email id like

Now you got an email id that makes the association between google cloud console, Google Indexing API, and Google search console.

Then manage a new key for the permanent association. So click the right side 3 dot option and go to manage keys.

Then we reached to keys section

then hit to add key and then click to create button and you got two key type option 1. JSON and 2. P12

Now we go with JSON option to create the key.

When you hit the create button you got a file of the private key to your computer.

The red mark box shows the downloaded file of the private key of JSON.

You got this file on the download folder of your computer. (In case of default settings)

Now you can ignore the tab of google developers console and time to make an association with Google Search Console and Google Indexing API.

So open the Google Search Console in a new tab and come to the dashboard.

Then go to the Users and permissions sections for the google service account associations.

Click on Add user and you got screen like this

Now you can enter the service account email id that’s have been created during «Fill up Service account details like a service account name.»

Now your Google Developers Console accounts, Google Indexing API, and Google Search Console are linked with each other.

Step 3: How to use Google Indexing API with python.

This will be a major step to use Google Indexing API for indexing web pages.

So first step will be a download and install python on your computer device.

Visit directly and download python from here: https://www.python.org/downloads/

After downloading the python, you should start installing python on your computer like this

When you get this popup screen of python, you must go to customize the installation like

and check all boxes before clicking the install button.

After installation Search python on your computer search bar like this

and you got a console like this

After python installation now creates a folder for Google Indexing API like this with the content of 3 files but first rename the download private account key to apidetails.json

Now enter the Window + R button and cmd

Now enter the command of «pip install oauth2client httplib2» in CMD

After this install the Pandas file in the CMD

The command is «pip install pandas»

Now move to indexing step, So open again CMD

and call the folder by giving a command. eg: our Indexing folder is on E drive. So give the command like this «drive name:»

Now go to the Folder like this, eg: «cd drivename:\indexing» then enter this

Читайте также:  Java for web api

Now enter the final command for the indexing process: python indexing.py

Here you send the bulk indexing request to google webmaster.

Источник

How to Use Google Indexing API For Beginners?

How to Use Google Indexing API For Beginners

Before understanding how to use Google Indexing API, know what exactly indexing API is? The indexing API notifies Google to know when a website owner adds or removes pages. Google indexed a page when a Google crawler visited and analysed it for content. But how beginners can use it to tell Google to remove or upgrade a page from its index. However, users use the indexing API to crawl pages.

Probably, you don’t have to be a computer programmer to be good at SEO, but most Google functions only be accessed through programming. In addition, Google introduces various APIs for large organizations with IT teams. But what if a non-programmer is willing to benefit from these SEO techniques? In this article, you will get to know how to set up and use Google Indexing API step by step.

Primarily understand the function of APIs.

Google developed APIs so that businesses can communicate with its services and their integration to other services. Different kinds of APIs are Google Maps, Search, Translate, Gmail, etc. function differently.

How to set up APIs

Several approaches can use Google Indexing APIs, but we will tell how Python Programming Language helps use it.

*Install Python to your computer

  • Click on download python and install it
  • Now, go to Google Developer Console (console.developers.google.com)

However, almost all the APIs are free to use, but there are some that ask for a payment, for which you have to add a billing account number.

Google Cloud Platform

So, after setting up a billing account, click on the top left icon on your computer screen

*Go to the APIs and services credential window

1. Service account details

Add Service account name and create service credentials

2. Grant this service account access to the project

3. Grant users access to this service account (Optional)

*You will shift to Service accounts for the project “search console.”

  • Copy email address
  • Go to Actions (select manage keys)
  • ADD KEY (create new key)
  • Select JSON (an authentication file will download automatically that will verify your API access)
  • Select APIs and Services
  • Go to library
  • Search indexing API
  • Select indexing API
  • Tap on enable button

*Go to Google Search Console

Google Search Console

Now, you have to go to the website on Google Search Console, the URL of which you want to send for indexing through Indexing API.

Then, go to the settings and click on users and permission

#paste email address that you have copied previously

Now, if you are using Mac, search terminal, and if windows, search CMD Command Prompt

Install libraries and use codes below

Code 1: pip install oauth2client httplib2

Code 1: pip3 install oauth2client httplib2

*Enter and then type second code

Code 2: pip install pandas

Code 2: pip3 install pandas

Now, you can finally be able to use Google Indexing API for your SEO.

How to use Google Indexing API through python script

Now you have three files to use Google Indexing API effectively. The first file is what you have downloaded from the Google developer console as a critical password authentication method. The second file should contain all those URLs that you want to index. The final and third file has all the python code used to run API. But first, put all these files in one folder as it is essential to use them properly. Now rename your first file as API details and remove it from the exact place where it is present.

Читайте также:  Java map get key with value

Now open the second file, and you will find your data here as the same. In addition, you can add URLs that you want to index in this file. Here you can add up to 1000 URLs at a time. Now come to the third file and run it. If you are a Mac user, then type terminal, and if windows, then type command prompt. After opening the terminal or command, you will shift to a folder where you have to choose CD space in Mac and paste the file pathways here. However, this is a different process in windows as you will find it by following the same trick.

Furthermore, after coming to the right folder, you (Mac user) have to type python3 indexing.py and press enter button. Similarly, Windows users have to type python indexing.py and press enter button. Through this process, Google will be notified about the URLs you want to index. And so, with timestamps, you can see the URLs update here. All the URLs in your second document will probably be sent to Google.

How to ensure you are using Google Indexing API appropriately

This would be the first question that will bother you whether this script is running properly or not. So, open the second file again in which you have saved your URLs. Now, remove all URLs from this file but leave one alone to check if the script is running. Again save the updated file and go back to the command prompt. Repeat the process as type python3 indexing.py or python indexing.py and run. What now? You will see the URL that you left for checking, and others will automatically disappear.

So, in this way, you can send the URLs indexing notifications to Google through Google Indexing API and a simple python script.

Moreover, this is the way by which you can send your website URL for indexing in bulk. But remember, will Google index these URLs or not will depend on your website and Googlebot. So, you just focus on the website’s content, quality, and other technical aspects.

Summary

However, it is easy to use Google Indexing API, but if you experience any issue, you can read more about it. Now, you know how to use Google Indexing API, and you can send notifications to Google regarding your URLs.

But, in case you want to take help from a digital marketing agency to put your business ahead of your competitors. When you use Google Indexing API, Google will receive notifications when you are adding or removing pages.

Moreover, if you want to collect extra information about how to use Google Indexing API, you can contact the experts of the SkySeoTech team.

Solve your queries associated with Digital Marketing Strategies by taking suggestions from the SkySeoTech team. Our market experts will help you resolve all your problems. Kindly contact us on the websites given below.

Источник

Оцените статью