Thursday, July 10, 2008

Example Java code for posting to using labels/tags

So I really can't believe how long it took to get this right, but here is some example code for posting to with the ability to add some tags or categories or labels.

You just try searching for some code example on how to "post to a blog using tags". Jeez, it took about 45 minutes of searching to find an actual post that WASN'T a blog post that had a tag.

public class GoogleBlogPostTest extends TestCase 
public void testBlogPost() throws Exception
GoogleService myService = new GoogleService("blogger", "company-xampleApp-1");
myService.setUserCredentials("googleusername", "googlepassword");

String title = "This is my title " + (new Date()).toString();
String blogID = "blognumber";
String contentStr = "This is a test of the emergency blogging system";
String authorName = "Test Author";
String userName = "";
String summary = "This is the summary";

ArrayList tags = new ArrayList();

Entry myEntry = new Entry();

for(String tag : tags)
Category category = new Category();

Content content = new TextContent(new PlainTextConstruct(contentStr));
myEntry.setTitle(new PlainTextConstruct(title));
Person author = new Person(authorName, "", userName);
myEntry.setSummary(new PlainTextConstruct(summary));

URL postUrl = new URL("" + blogID + "/posts/default");

Entry newEntry = myService.insert(postUrl, myEntry);

assertEquals(title, newEntry.getTitle().getPlainText());


Anonymous said...

Who knows where to download XRumer 5.0 Palladium?
Help, please. All recommend this program to effectively advertise on the Internet, this is the best program!

Johnny Adams said...

It's very nice of you to share your knowledge through posts. I love to read stories about your experiences. They're very useful and interesting. I am excited to read the next posts. I'm so grateful for all that you've done. Keep plugging. Many viewers like me fancy your writing. Thank you for sharing precious information with us. Best facebook reviews joomla service provider