
This document is intended for Apex Developers who want to write Force.com Apps that can interact with Google's Blogger Data API.
This document assumes that you understand the general ideas behind the Google Data APIs protocol.
For additional Google Blogger Data API reference information, see the Google Blogger Data API Reference Guide.
The Force.com platform is the most scalable, secure and popular on-demand platform in the world today. You can develop and instantaneously deploy applications without any infrastructure - 100% on-demand
The Force.com IDE allows developers a full-featured, Eclipse-based coding environment, with capabilities like code completion, version control,collaborative development, and project sharing.
Google Blogs are associated with Google Accounts, so a Google Account will be required in order to proceed. To view your blogs without using the Blogger Data API, you can log in to Gmail and click the Blogs link.
Check out the Force.com Toolkit for Google Data APIs from the Google repository.
The following examples show how to send Google Blogger Data API requests from Apex Code.
Create the Apex object that will handle the connection to Google Blogger Data API
BloggerService service = new BloggerService(); service.setAuthSubToken(sessionAuthToken);
Call the getFeed method, with the default feed url string to list all blogs for this user.
GoogleData allBlogs = service.getFeed( BloggerService.defaultFeed ); allBlogs.dump();
The Blogger Data API provides a feed that lists the blogs for a particular user; that feed is known as a "metafeed." The following sample code uses an authenticated GoogleService object to connect to a blog (MyBlog), retrieve posts and print out title and content.
xmldom.element oneBlog = service.getBlogTitle( 'MyBlog' );
GoogleData posts = service.getFeed(
GoogleData.getRelLink(oneBlog, BloggerService.entryFeed) );
system.debug( posts.entries[0].getValue('title') );
system.debug( posts.entries[0].getValue('content') );
The Blogger Data API allows you to create and publish new blog entries, as well as creating drafts of entries.
You can publish new blog entries directly from Apex code. First, create an Entry object to represent the blog post. Then you can set the title, content and other attributes of the blog post. Finally, use the service object to insert the post. Here's an example of how to publish a new blog post from Apex:
// get the blog to post into
xmldom.element oneBlog = service.getBlogTitle( 'testforce' );
xmldom.element atom = service.makeBlogElement('Marriage!','Liz','liz@mail.com');
service.setContent( atom,
'<p>Mr. Darcy has <em>proposed marriage</em> to me!</p>'+
'<p>He is the last man on earth I would ever desire to marry.</p>'+
'<p>Whatever shall I do?</p>' );
service.insertEntry(oneBlog, atom );
Draft posts are created in the same way as public posts, but you need to set the draft attribute of the Entry object. You can create a blog post like the one above as a draft by adding the highlighted line:
// blog to post to
xmldom.element oneBlog = service.getBlogTitle( 'testforce' );
xmldom.element atom = service.makeBlogElement('Marriage!','Liz','liz@gmail.com');
service.setContent( atom,
'<p>Mr. Darcy has <em>proposed marriage</em> to me!</p>'+
'<p>He is the last man on earth I would ever desire to marry.</p>'+
'<p>Whatever shall I do?</p>' );
service.setDraft(atom ); // mark this post as draft, not public
service.insertEntry(oneBlog, atom );
You can turn an existing draft blog post into a published post by retrieving the draft post, setting the draft attribute to false, and then updating the post.
The following sections describe how to retrieve a list of blog posts, with and without query parameters.
To retrieve the user's posts, call the same getFeed method used to retrieve the blogs metafeed:
GoogleData allBlogs = service.getFeed( BloggerService.defaultFeed );
allBlogs.dump();
system.debug( allBlogs.entries[0].getValue('id') );
xmldom.element oneBlog = allBlogs.entries[0];
string postFeedUrl = GoogleData.getRelLink(oneBlog, BloggerService.postUrl);
GoogleData posts = service.getFeed( postFeedUrl );
posts.dump();
The Blogger Data API lets you request a set of entries that match specified criteria, such as requesting blog posts created or updated in a given date range. To do this, you append query parameters to the default feed and pass it to the service object getFeed() method.
For example, to send a date-range query, use the setUpdatedMin and setUpdatedMax methods of the Query object. The following Apex code snippet returns one blog from the users blog list
GoogleData oneBlog = service.getFeed( BloggerService.defaultFeed + '?max-results=1' ); oneBlog.dump();
The Blogger Data API supports the following Query methods:
For more information about query parameters, see the Blogger Data API Reference Guide and the Google Data APIs Reference Guide.
To update an existing blog post, first you retrieve the entry you want to update, then you modify it, and then you send it to Blogger. No support for update exists at this time within the force.com library.
To delete a post, pass the post's edit id to the GoogleService object, no example available at this time.
The Blogger Data API allows for creating, retrieving, and deleting comments. Updating comments is not supported (nor is it available in the web interface). The Apex library does not currently contain methods for this, they can be developed using the BloggerService class as an example, and extend it to meet this need.