Monday, October 13, 2008 at 2:18 PM
The Webmaster Tools GData API has been updated to allow you to get even more out of Webmaster Tools, such as setting a geographic location or your preferred domain. For those of you that aren't familiar with GData, it's a protocol for reading and writing data on the web. GData makes it very easy to communicate with many Google services, like Webmaster Tools. The Webmaster Tools GData API already allows you to add and verify sites for your account and to submit Sitemaps programmatically. Now you can also access and update site-specific information. This is especially useful if you have a large number of sites. With the Webmaster Tools API, you can perform hundreds of operations in the time that it would take to add and verify a single site through the web interface.
What can I do?
We've included four new features in the API. You can see and update these settings for each site that you have verified. The features are:
We provide you with Java code samples for all the current Webmaster Tools API functionality. Here's a sample snippet of code that takes a list of sites and updates the geographic location of all of them:
// Authenticate against the Webmaster Tools service
WebmasterToolsService service;
try {
service = new WebmasterToolsService("exampleCo-exampleApp-1");
service.setUserCredentials(USERNAME, PASSWORD);
} catch (AuthenticationException e) {
System.out.println("Error while authenticating.");
return;
}
// Read sites and geolocations from your database
readSitesAndGeolocations(sitesList, geolocationsList);
// Update all sites
Iterator sites = sitesList.iterator();
Iterator geolocations = geolocationsList.iterator();
while (sites.hasNext() && geolocations.hasNext()) {
// Create a blank entry and add the updated information
SitesEntry updateEntry = new SitesEntry();
updateEntry.setGeolocation(geolocations.next());
// Get the URL to update the site
String encodedSiteId = URLEncoder.encode(sites.next(),
"UTF-8");
URL siteUrl = new URL(
"http://www.google.com/webmasters/tools/feeds/sites/"
+ encodedSiteId);
// Update the site
service.update(siteUrl, updateEntry);
}
Where do I get it?
The main page for the Webmaster Tools GData API explains all the details of the API. It has a detailed reference guide and also many code snippets that explain how to use the Java client library, which is available for download. You can find more details about GData and all the different Google APIs in the Google Data API homepage.
What can I do?
We've included four new features in the API. You can see and update these settings for each site that you have verified. The features are:
- Crawl Rate: You can request that Googlebot crawl your site slower or faster than it normally would (the details can be found in our Help Center article about crawl rate control). If many of your sites are hosted on the same server and you know your server's capacity, you may want to update all sites at the same time. This now a trivial task using the Webmaster Tools GData API.
- Geographic Location: If your site is targeted towards a particular geographic location but your domain doesn't reflect that (for example with a .com domain), you can provide information to help us determine where your target users are located.
- Preferred Domain: You can select which is the canonical domain to use to index your pages. For example, if you have a site like www.example.com, you can set either example.com or www.example.com as the preferred domain to use. This avoids the risk of treating both sites differently.
- Enhanced Image Search: Tools like the Google Image Labeler allow users to tag images in order to improve Image Search results. Now you can opt in or out for all your sites in a breeze using the Webmaster Tools API.
We provide you with Java code samples for all the current Webmaster Tools API functionality. Here's a sample snippet of code that takes a list of sites and updates the geographic location of all of them:
// Authenticate against the Webmaster Tools service
WebmasterToolsService service;
try {
service = new WebmasterToolsService("exampleCo-exampleApp-1");
service.setUserCredentials(USERNAME, PASSWORD);
} catch (AuthenticationException e) {
System.out.println("Error while authenticating.");
return;
}
// Read sites and geolocations from your database
readSitesAndGeolocations(sitesList, geolocationsList);
// Update all sites
Iterator
Iterator
while (sites.hasNext() && geolocations.hasNext()) {
// Create a blank entry and add the updated information
SitesEntry updateEntry = new SitesEntry();
updateEntry.setGeolocation(geolocations.next());
// Get the URL to update the site
String encodedSiteId = URLEncoder.encode(sites.next(),
"UTF-8");
URL siteUrl = new URL(
"http://www.google.com/webmasters/tools/feeds/sites/"
+ encodedSiteId);
// Update the site
service.update(siteUrl, updateEntry);
}
Where do I get it?
The main page for the Webmaster Tools GData API explains all the details of the API. It has a detailed reference guide and also many code snippets that explain how to use the Java client library, which is available for download. You can find more details about GData and all the different Google APIs in the Google Data API homepage.


9 comments:
Hi Google team,
There is a problem with the Export tool you provide for Europeans likes me.
The CSV format doesn't match the expected format for Excel French Edition. The default separator is ";" in FR instead of "," presently.
Is it possible to get an option for export settings ?
Thanks in advance !
Hello, thanks for this article. I wonder if it's possible to get the content of the CSV table directly from the API (not manually through the interface). That would be cool, really.
Hello, finally got my API code working, thanks. Now I became appetite for more:
- the information provided by an "individual Sitemap entry" is currently only a simple subset of the "Sitemaps feed" and does not correspond to the submenue of the webpage, missing "indexed URLs in Sitemap"
- to get the crawl stats via the API would be most attractive.
Anyway, keep up the good work!
Is there a way I can also get the link details from webmaster console?
Hi Javier, great post ! What I understand from http://best-seo-optimization-tips.co.uk/ is that the Geographic settings in WMT only work when a searcher checks "Pages From" in Google search engine. Is that correct ?
Hi, I'm trying to get the sample webmaster tools code to work and I keep getting an error when trying to list out the sites in my webmaster tools account. I would post on the forum but I can't seem to get a response and I see at least one other person on the forum having the same issue. Is there a better place to get feedback on the api other than the general webmaster tools group?
The error I'm getting is:
com.google.gdata.util.ParseException: [Line 1, Column 2522, element wt:verification-method] Unknown attribute: 'file-content'
Hi Dadonk, thanks for posting! From what I hear, it should be ok now :-).
Cheers
John
Do you have the same example in PHP? I've been learning PHP and implemented blogger autopost using zend_gdata based on someones' code. I'm not totally fluent in PHP nor zend_gdata, but java will push me back several months back.
Pls share if you have in PHP,
many thanks
Hi everyone,
Since over a year has passed since we published this post, we're closing the comments to help us focus on the work ahead. If you still have a question or comment you'd like to discuss, free to visit and/or post your topic in our Webmaster Central Help Forum.
Thanks and take care,
The Webmaster Central Team
Post a Comment