Tuesday 10 September 2013

How to Get Top Search Queries Data from Webmaster Tools API

Here's how to get a .csv file of your latest Search Query report from the Google Webmaster Tools API.

Go download the gwdata.php api file here.

Here's sample code from the docs which grabs a .csv of your latest Search Query report and saves it in the same folder.

<?php
include 'gwtdata.php';
try {
$email = "XXXXX";
$password = "XXXXX";
# If hardcoded, don't forget trailing slash! $website = "http://nerdygoodness.wordpress.com/";
# Valid values are "TOP_PAGES", "TOP_QUERIES", "CRAWL_ERRORS",
# "CONTENT_ERRORS", "CONTENT_KEYWORDS", "INTERNAL_LINKS",
# "EXTERNAL_LINKS" and "SOCIAL_ACTIVITY".
$tables = array("TOP_QUERIES");
$gdata = new GWTdata();
if($gdata->LogIn($email, $password) === true)
{
$gdata->SetTables($tables);
$gdata->DownloadCSV($website);
}
} catch (Exception $e) {
die($e->getMessage());
}
?>

I've run this code to get the top search query report from my other blog nerdygoodness.wordpress.com. The results of which can be seen here.

No comments: