Saturday, 18 June 2011

Howto Change Blogger Settings with the GData API

I've just discovered an undocumented (or I couldn't find any docs for it anyways) way to change the settings of your Blogger/Blogspot blog via the GoogleData API.

I discovered this as a result of the recent 'breakage' of my API client. I was using a blog-posting 'endpoint' URL that wasn't supposed to work, but had been working until recenty. That was a url of the form:

http://idratherhack.blogspot.com/feeds/posts/default


But apparently I should have been looking up a special url of the form:

http://www.blogger.com/feeds/8441087078477003568/posts/default

Where the long number is a unique ID for my blog.

To get this special url, you have to first authenticate, and then do a GET to:

http://www.blogger.com/feeds/default/blogs

This will return a big ol' mess o' XML:


<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/' xmlns:gd='http://schemas.google.com/g/2005' gd:etag='W/&quot;A04NRno-fip7ImA9WhZbE0Q.&quot;'><id>tag:blogger.com,1999:user-04780753778872137937.blogs</id><updated>2011-06-18T12:26:37.456Z</updated><title>Colum's Blogs</title>
<link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.blogger.com/feeds/04780753778872137937/blogs'/>
<link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/04780753778872137937/blogs'/>
<link rel='alternate' type='text/html' href='http://www.blogger.com/profile/04780753778872137937'/>
<author>
<name>Colum</name>
<uri>http://www.blogger.com/profile/04780753778872137937</uri>
<email>noreply@blogger.com</email>
</author>
<generator version='7.00' uri='http://www.blogger.com'> Blogger</generator>
<openSearch:totalResults>2</openSearch:totalResults>
<openSearch:startIndex>1</openSearch:startIndex>
<openSearch:itemsPerPage>25</openSearch:itemsPerPage>
<entry gd:etag='W/&quot;DUICSH49cSp7ImA9WhZbE0Q.&quot;'>
<id>tag:blogger.com,1999:user-04780753778872137937.blog-8441087078477003568</id>
<published>2009-11-29T11:35:11.006-08:00</published>
<updated>2011-06-18T04:46:09.069-07:00</updated>
<title>I'd Rather Hack</title>
<summary type='html'>Being the technical blog of Colum Paget, rather than his 'ranting into the void' one.</summary>
<link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/04780753778872137937/blogs/8441087078477003568'/>
<link rel='alternate' type='text/html' href='http://idratherhack.blogspot.com/'/>
<link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://idratherhack.blogspot.com/feeds/posts/default'/>
<link rel='http://schemas.google.com/g/2005#post' type='application/atom+xml' href='http://www.blogger.com/feeds/8441087078477003568/posts/default'/>
<link rel='http://schemas.google.com/blogger/2008#template' type='application/atom+xml' href='http://www.blogger.com/feeds/8441087078477003568/template'/>
<link rel='http://schemas.google.com/blogger/2008#settings' type='application/atom+xml' href='http://www.blogger.com/feeds/8441087078477003568/settings'/>
<author>
<name>Colum</name>
<uri>http://www.blogger.com/profile/04780753778872137937</uri>
<email>noreply@blogger.com</email>
</author>
<gd:extendedProperty name='IS_PUBLIC_BLOG' value='true'/>
<gd:extendedProperty name='PICASAWEB_ALBUM_ID' value='5570923802870618657'/>
</entry>
<entry gd:etag='W/&quot;C08NR3oyeyp7ImA9WhZUGEQ.&quot;'>
<id>tag:blogger.com,1999:user-04780753778872137937.blog-8531648592648053901</id>
<published>2009-10-19T18:36:24.631+01:00</published>
<updated>2011-06-12T16:18:16.493+01:00</updated>
<title>The Singularity Sucks</title>
<summary type='html'> The 21st century doesn't live up to the promises made when I sold my soul to SF back in the 70's, and I want my money back.</summary>
<link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/04780753778872137937/blogs/8531648592648053901'/>
<link rel='alternate' type='text/html' href='http://thesingularitysucks.blogspot.com/'/>
<link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://thesingularitysucks.blogspot.com/feeds/posts/default'/>
<link rel='http://schemas.google.com/g/2005#post' type='application/atom+xml' href='http://www.blogger.com/feeds/8531648592648053901/posts/default'/>
<link rel='http://schemas.google.com/blogger/2008#template' type='application/atom+xml' href='http://www.blogger.com/feeds/8531648592648053901/template'/>
<link rel='http://schemas.google.com/blogger/2008#settings' type='application/atom+xml' href='http://www.blogger.com/feeds/8531648592648053901/settings'/>
<author>
<name>Colum</name>
<uri>http://www.blogger.com/profile/04780753778872137937</uri>
<email>noreply@blogger.com</email>
</author>
<gd:extendedProperty name='IS_PUBLIC_BLOG' value='true'/>
<gd:extendedProperty name='PICASAWEB_ALBUM_ID' value='5397308624374094369'/>
</entry>
</feed>


Pretty gnarly, huh? It's even worse than this, I've cut a lot of stuff out.

Notice that in all that guff, there are two <entry> um... entries, that contain the information for my two blogs. Some of that information is a bunch of 'link' entries, that tell you the URLs (or 'endpoints') to use for certain REST operations (like posting a blog entry). Each has a 'rel' parameter that specifies what the url is for.

For posting blog entries, you should be using the one marked 'rel=http://schemas.google.com/g/2005#post', (which in this example is 'http://www.blogger.com/feeds/8531648592648053901/posts/default')

Howerver, there's two others that are mysterious to me, but interesting looking. These are the ones marked

rel='http://schemas.google.com/blogger/2008#template'
rel='http://schemas.google.com/blogger/2008#settings'

What can they be for?

Well, doing a GET to http://www.blogger.com/feeds/8531648592648053901/settings produces a vertiable deluge of XML. There's far too much of it to post here, but it's made up of entries like:


<entry gd:etag='W/&quot;C0QDSHo4eCp7ImA9WhZbE0U.&quot;'>
<id>tag:blogger.com,1999:blog-8441087078477003568.settings.BLOG_ADMIN_PERMISSION</id>
<published>2009-11-29T11:35:11.006-08:00</published>
<updated>2011-06-18T00:16:19.430-07:00</updated>
<app:edited xmlns:app='http://www.w3.org/2007/app'>2011-06-18T00:16:19.430-07:00</app:edited>
<category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/blogger/2008/kind#settings'/>
<title>The list of administrators' emails for the blog.</title>
<content>admin@googlemail.com</content>
<link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8441087078477003568/settings/BLOG_ADMIN_PERMISSION'/>
<link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8441087078477003568/settings/BLOG_ADMIN_PERMISSION'/>
</entry>


Each entry refers to one setting related to your blog. The 'title' tags enclose a description of what the setting is, and the 'content' tags enclose the value of the setting.

Notice that there's a 'link' tag with a parameter of 'rel=edit'. Normally these 'edit' links can be used to send data to a google service. I wondered if this link could be used to change the settings related to my blog?

Turns out that yes, they can.

Doing an HTTP PUT to the 'edit' url of the setting thusly:


PUT /feeds/8441087078477003568/settings/BLOG_BACKLINKS_ALLOWED HTTP/1.1
Host: www.blogger.com
Content-Type: application/atom+xml
Content-Length: 342
Connection: Close
GData-Version: 2.0
Authorization: GoogleLogin auth=<Your auth token goes here>

<?xml version='1.0' encoding='UTF-8'?><entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005'><category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/blogger/2008/kind#settings'/><id>tag:blogger.com,1999:blog.settings.BLOG_BACKLINKS_ALLOWED</id><content>true</content></entry>



Allows you to change a setting. You should get a 200 OK response if it worked.

Notice that you need to have this an id tag like this:

<id>tag:blogger.com,1999:blog.settings.BLOG_BACKLINKS_ALLOWED</id>

Basically change 'BLOG_BACKLINKS_ALLOWED' for the name of whatever setting you're changing.

And that's it. Have fun.

5 comments: