My New Photo Site has approximately 475 albums. Each album has manually coded RSS feeds. Now submitting that much RSS feeds, one by one, into Google Webmaster Tool’s interface is quiet painful.

So, I digged into Google’s GDATA API Code provided by Zend Framework. It’s very easy to submit google sitemap using php coding.

Steps:-
(1) Download Zend FrameWork
(2) Download GData API
(3) Write the code written @ end of the post into your php file & save it on path /demos/Zend/Gdata & run it.

Google needs RDF data tobe submitted to  https://www.google.com/webmasters/tools/feeds/www.yoursite.com/sitemap using POST request.

RDF format for submitting sitemaps is,

<atom:entry>
<atom:id>http://www.example.com/sitemap-index.xml</atom:id>
<atom:category scheme='http://schemas.google.com/g/2005#kind'
term='http://schemas.google.com/webmasters/tools/2007#sitemap-regular'/>
<wt:sitemap-type>WEB</wt:sitemap-type>
</atom:entry>

You need to change http://www.yoursite.com/sitemap.xml with your sitemap location dynamically using php.

Above XML was creating some parsing errors before submitting POST request because it has no name-space.

So, I googled some different xml for submitting SiteMap,

<entry xmlns="http://www.w3.org/2005/Atom" xmlns:wt="http://schemas.google.com/webmasters/tools/2007">
<id>http://www.yoursite.com/sitemap.xml</id>
<category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/webmasters/tools/2007#sitemap-regular'/>
<wt:sitemap-type>WEB</wt:sitemap-type>
</entry>

So final php code became.

<?php

require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Gapps');

// Provide Google Account Information
$email = 'youremail@gmail.com';
$passwd = 'xxxxxxxx';
$service      = 'sitemaps';

// Try to connect
try {
$client = Zend_Gdata_ClientLogin::getHttpClient($email, $passwd, $service);
} catch (Zend_Gdata_App_CaptchaRequiredException $cre) {
echo 'URL of CAPTCHA image: ' . $cre->getCaptchaUrl() . "n";
echo 'Token ID: ' . $cre->getCaptchaToken() . "n";
} catch (Zend_Gdata_App_AuthException $ae) {
echo 'Problem authenticating: ' . $ae->exception() . "n";
}

add_sitemap($sitemap-location,$client);

function add_sitemap($sitemap-location,$client){
$xml ='<entry xmlns="http://www.w3.org/2005/Atom" xmlns:wt="http://schemas.google.com/webmasters/tools/2007"><id>'.$sitemap-location.'</id>';
$xml.="<category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/webmasters/tools/2007#sitemap-regular'/><wt:sitemap-type>WEB</wt:sitemap-type></entry>";
$fdata = new Zend_Gdata($client);
$result=$fdata->post($xml,”https://www.google.com/webmasters/tools/feeds/http://yoursite%2Ecom%2F/sitemaps/”,null,”application/atom+xml”);
}

?>