I’m sure I’ll have some fun later messing with the Zend Gdata classes in PHP, it looks to be great for interfacing with practically every google api except the one I wanted, webmaster tools. I could get authenticated to the webmaster tools scope using zend, and even pull a full sites feed for my account, but after that the included classes just aren’t built to handle the flavor of atom feed returned by the webmaster api.I couldn’t pull an individual site’s feed, and I couldn’t request a site verification, which was my primary goal.
After messing with it for probably too long, I decided to try a different approach. The gdata-python-client library is where I should’ve started all along. The out of the box sample apps for webmaster tools work flawlessly, and use the client auth type to hook you in to the api.
I did need to modify the code in version 1.2.3 of the library a tiny bit to make the VerifySite() function work, luckily it’s an easy fix. Below is a snippet from src/gdata/webmastertools/__init__.py line 126. My changes are in red.
class VerificationMethod(atom.AtomBase):
_tag = ‘verification-method’
_namespace = GWEBMASTERTOOLS_NAMESPACE
_children = atom.Text._children.copy()
_attributes = atom.Text._attributes.copy()
_children['{%s}meta' % atom.ATOM_NAMESPACE] = (
‘meta’, VerificationMethodMeta)
_attributes['in-use'] = ‘in_use’
_attributes['type'] = ‘type’
def __init__(self, text=None, in_use=None, type=None, meta=None,
extension_elements=None, extension_attributes=None):
self.text = text
self.in_use = in_use
self.type = type
self.meta = meta
self.extension_elements = extension_elements or []
self.extension_attributes = extension_attributes or {}
And a snippet from src/gdata/webmastertools/service.py line 153. Again, the change is in red.
site_entry = webmastertools.SitesEntry(
atom_id=atom.Id(text=site_uri),
category=atom.Category(
scheme=’http://schemas.google.com/g/2005#kind’,
term=’http://schemas.google.com/webmasters/tools/2007#sites-info’),
verification_method=webmastertools.VerificationMethod(
type=verification_method, in_use=’true’)
)
Don’t forget to recompile the libs with a python ./setup.py install after making these changes, and you’ll be able to script all the site verifications you want. Next step is throwing together a set of scripts to allow for complete site management in webmaster tools, looks like Python’s gonna make it a snap!




I’ve been working more or less without break since the start of work on Tuesday. I’m exhausted but my mind won’t shut off so here I am brushing the dust off my blog and finally making my first post! Still don’t know what it is I mean to do with this blog, but since I’m new to the whole social media crowd, I figured it’d be a good way to journal my discoveries in that arena, and provide vent space for anything I can dream up a category for. Right now I’m day-dreaming of electric sheep so I think that’s a good sign to go recharge and become human again.