How to Retrieve Your Google Search Console Data via API

by Oliver 8. September 2017 00:04

To set up API access to a site's Search Console, we first need to set up and configure a project in the Google Developer Console. Afterwards, we will connect that project to the Search Console to retrieve data from there using our own application.

In the Google Developer Console

  1. Set up a project in your Google Developer Console (or reuse an existing project).
  2. Go to the Service Accounts page and click [+] CREATE SERVICE ACCOUNT:
    gapi-service-account
    Check "Furnish a new private key" to retrieve a JSON file with credentials that can be used from your application to impersonate that account.
  3. Save the file that is being offered as a download. Its name has the form <ProjectId>-<Hash>.json, e.g. discoverize-b134aef29b12.json. This file is confedential – anyone with access to it can do what your Service Account is allowed to! So treat it respectively.
  4. Go to the project dashboard and click [+] ENABLE APIS AND SERVICES:
    gapi-library-search-console
  5. Click on the Google Search Console API link and on the next page click ENABLE.

That's what had to be done in the Google Developer Console.

Now we'll turn to the Google Search Console aka Webmaster Tools.

In the Google Search Console

  1. Make sure you have a property set up in the Search Console for the target site. Let's assume you're targeting https://glamping.info. The protocol is of importance: http://glamping.info and https://glamping.info will be two different properties.
  2. In the settings drop-down menu, go to Users and Property Owners:
    search-console-menu
  3. Click ADD A NEW USER (do not Manage Property Owners):
    search-console-add-user
    Add the email address of the Service Account you've created in Google Developer Console and give it Full permission.
    Note: do NOT add the Service Account as a Property Owner before adding it as a user, otherwise API access using it will NOT work. This is a bug – see this stackoverflow answer for more details.
  4. When you click Add, you'll see the new user on the Users and Property Owners page:
    search-console-users-overview

Now, you're all set up to access your site's Search Console using the Google API.

Happy coding!

Comments are closed

About Oliver

shades-of-orange.com code blog logo I build web applications using ASP.NET and have a passion for javascript. Enjoy MVC 4 and Orchard CMS, and I do TDD whenever I can. I like clean code. Love to spend time with my wife and our children. My profile on Stack Exchange, a network of free, community-driven Q&A sites

About Anton

shades-of-orange.com code blog logo I'm a software developer at teamaton. I code in C# and work with MVC, Orchard, SpecFlow, Coypu and NHibernate. I enjoy beach volleyball, board games and Coke.