Retrieving Your BloggerBeta Blog ID
Some people are wondering how to programatically get the blogID
that the
Google Data API page keeps referring to. I'm not sure if this is the
best way or not, but I've had success using the following method in Python:
def getBlogID(uri): import httplib2, re con = httplib2.Http() response, content = con.request(uri, 'GET') match = re.search('blogID=(\d*)', content) if match: return match.group(1) else: print "BlogID retrieval failed."
It's quite simple actually, it takes your blog's URL as a parameter (as in http://whatever.blogspot.com),
and sends an empty GET
request to it. The response returned contains a string
that matches the regular expression blogID=(\d*)
. That is, the string "blogID=" followed
by a bunch of numbers. That bunch of numbers is the blogID. The function shown above
extracts that number with a regular expression, and returns it.
No comments:
Post a Comment