First download and install Google API from here:
http://code.google.com/p/google-gdata/downloads/list

Add a reference to “Google Data API Core Library”,
and use the following function:

public static bool AddPost(string title, string bodyHTML, string[] labels)
{
    Service service = new Service(“blogger”, “<program name>”);
    service.Credentials = new GDataCredentials(“<username>”, “<password>”);
    AtomEntry newPost = new AtomEntry();
    newPost.Title.Text = title;
    newPost.Content = new AtomContent();
    newPost.Content.Content = bodyHTML;
    newPost.Content.Type = “html”;
    foreach (string label in labels)
    {
        AtomCategory cat = new AtomCategory();
        cat.Scheme = new Uri(“http://www.blogger.com/atom/ns#”);
        cat.Term = label;
        newPost.Categories.Add(cat);
    }
    AtomEntry response = null;
    try
    {
        response = service.Insert(new Uri(“<uri>”), newPost);
    }
    catch (GDataRequestException exception)
    {
        if (exception.ResponseString == “Blog has exceeded rate limit or otherwise requires word verification for new posts”)
        {
            return false;
        }
        else
        {
            throw exception;
        }
    }
    if (response == null)
    {
        throw new Exception(“Something went wrong”);
    }
    return true;
}

Note what you need to replace:

  • <program name>
  • <username>
  • <password>
  • <uri>

Also note the marked yellow line. It took me some nasty googling time to find it. You must put it for the labels to work.

By Enrico

My greatest passion is technology. I am interested in multiple fields and I have a lot of experience in software design and development. I started professional development when I was 6 years. Today I am a strong full-stack .NET developer (C#, Xamarin, Azure)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.