Using Google Blogger Data Api to implement auto-post

I have a php program running on Dreamhost daily to rip and convert the audio file from another website, which is used by itunes only. I want to make it blogger friendly so auto-post is a must-have feature. It turns out Google Api is the best solution. (wordpress seems don’t have this yet?)

Currently, gdata api only support Java, dotNet, php and Python. (Shocked! No Ruby!) My php version on DH is 4XX but gdata needs 5XX. dotNet is impossible on Linux and I don’t want waste time on Java, I had to study a little bit Python. After half-hour learning, I regret I should know Python earlier. It’s so powerful and easy to configure, except it’s stupid force-indent coding style.

Anyway, I made it working on my DH now. The trick is to add a line to import my local python library provided by Gdata.

import sys

New update: It seems google has a spam control for this auto-post api,
you can not create more than 50 post within 24 hours.
So please keep patient when you are moving blog into google. It takes days.


13 thoughts on “Using Google Blogger Data Api to implement auto-post

  1. Suppose i have 2 selection box in PHP technology. 1 is for country and 2nd ia for state. i want according to country
    selection show the related state in selection box 2.
    How is possible. Please send me code.

  2. Awesome Website Frank, Alot of Useful Information.
    Can you help me make an auto post script.
    How can I contact you. Please reply with aim or yim sn.

  3. #!/usr/bin/python
    # Copyright (C) 2007 Google Inc.
    __author__ = ' (Luke Keppler)'
    import sys
      from xml.etree import ElementTree # for Python 2.5 users
      from elementtree import ElementTree
    from gdata import service
    import gdata
    import atom
    import getopt
    import feedparser
    class BloggerExample:
      def __init__(self, email, password):
        """Creates a GDataService and provides ClientLogin auth details to it.
        The email and password are required arguments for ClientLogin.  The
        'source' defined below is an arbitrary string, but should be used to
        reference your name or the name of your organization, the app name and
        version, with '-' between each of the three values."""
        # Authenticate using ClientLogin.
        self.service = service.GDataService(email, password)
        self.service.source = 'Blogger_Python_Sample-1.0'
        self.service.service = 'blogger'
        self.service.server = ''
        # Get the blog ID for the first blog.
        feed = self.service.Get('/feeds/default/blogs')
    	# hard code blog_id
        self.blog_id = "123123123312312312"
        self_link = feed.entry[0].GetSelfLink()
        if self_link:
          #self.blog_id = self_link.href.split('/')[-1]
          # If you have multiple blogs, hardcode to set the one you want.
          self.blog_id = "131231231231212312"
      def CreatePost(self, title, content, author_name, is_draft):
        # Create the entry to insert.
        entry = gdata.GDataEntry()
        entry.title = atom.Title('xhtml', title)
        entry.content = atom.Content('html', '', content)
        if is_draft:
          control = atom.Control()
          control.draft = atom.Draft(text='yes')
          entry.control = control
        # Ask the service to insert the new entry.
        return self.service.Post(entry, '/feeds/' + self.blog_id + '/posts/default')
      def run(self):
          public_post = self.CreatePost("test","<p>test</p>","Post author", False)
          print "Job finished."
    def main():
      email = "your blogger user id"
      password = "your password"
      sample = BloggerExample(email, password)
    if __name__ == '__main__':

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s