update 2: Sandrine worked out a set of routines, as far as I know using Zend 1.7, she lists the code here.
update: Google updated their API in oktober (almost at the time I wrote these posts) and this code fails as it still based on the V1 APi. You can access the whole WT: toolset namespace (including sitemaps, verification) through the V2 API now, but you need to send a version id along with your request, that is handled in the new Zend 1.7 download.
The Problem
I can add 32.000 blogs on a standard WordPressMu install. How do I add 32.000 subdomains, verify them and add their sitemaps to Google Webmaster, without having to go to the webmaster page about 96.000 times ?
The solution
Integrating Google Webmaster Tools API into my WordPress Mu install.
What is it worth ?
If registering and verifying a site and adding a sitemap takes 5 minutes per domain, at E12,- per hour, that makes it 96.000 euros and 4 labor years for 32.000 sites. Writing a script is worth E96.000,- and saves me four years of mindless drone work, so that is well worth having a look at.
Software : Zend
Zend gData is a php framework that is programmed to handle Google Data. Their ClientLogin routine isn’t very flexible and they haven’t covered GWT Api yet, so I’ll have to hack some routines together.
After getting stonewalled by the zend program a few times, I went searching and ended up on ngoprekweb who have a nice post on ClientLogin authorization for the blogger api. Eris Ristemena uses a modified Zend ClientLogin, very nice work. I installed the adapted classes and tried that one to get through the ClientLogin, and it paid off.
The good stuff : Gwt api access
I am not interested in the blogger stuff though, I want access to GWT Google Webmaster Tools, so I worked Eris Ristemena’s blogger routine around a little.
-
require_once 'Zend.php';
-
Zend::loadClass('Zend_Gdata_ClientLogin');
-
Zend::loadClass('Zend_Gdata');
-
Zend::loadClass('Zend_Feed');
-
-
$username = '';
-
$password = '';
-
$service = 'sitemaps';
-
$source = 'Zend_ZendFramework-0.1.1'; // companyName-applicationName-versionID
-
$logintoken = $_POST['captchatoken'];
-
$logincaptcha = $_POST['captchaanswer'];
-
-
try {
-
$resp = Zend_Gdata_ClientLogin::getClientLoginAuth($username,$password,$service,$source,$logintoken,$logincaptcha);
-
-
if ( $resp['response']=='authorized' )
-
{
-
$client = Zend_Gdata_ClientLogin::getHttpClient($resp['auth']);
-
$gdata = new Zend_Gdata($client);
-
-
$feed = $gdata->getFeed("https://www.google.com/webmasters/tools/feeds/sites/");
-
foreach ($feed as $item) {
-
echo '
-
You saved my life!!
thank you
Hello,
I did exactly how you did and it worked for 30 websites.
but once i wanted to add my 2102 websites i got one error messages :Fatal error: Maximum execution time of 30 seconds exceeded in /www/hosts/googlewebmaster/html/library/Zend/Uri/Http.php on line 64
Did you get the same error? if yes do you know where i can change the timestamp?
Thanks
A standard php install has a time limit in php.ini of 30 seconds (to prevent a function from running on endless on the server, usually when it gets stuck on http-connections not returning data). You can call set_time_limit(); inside the loop to reset the 30 second count, providing your host doesn’t use safe mode. Some scripts use set_time_limit(0); at the beginning of a script which sets the limit off, but that can backfire. It indicates a problem with the http-connection, do you login for every site you add, or login and use one client to add the whole site list, in a loop ?
Urgh, the Markup is really messed up here. Please spend a minute on that! There are not so many resources on acessing GWT via PHP as it’s the case for other languages like Python & co. I.e. if we want to learn how it works, then your website is one of the few opportunities we have. Don’t disappoint us.