Want to look up the URL for a post retrieved using the Blogger API? If you're using the .NET client library, you can do it with one line of C# code:
string postUrl = entry.AlternateUri.Content;
Want to look up the URL for a post retrieved using the Blogger API? If you're using the .NET client library, you can do it with one line of C# code:
string postUrl = entry.AlternateUri.Content;
<entry xmlns="http://www.w3.org/2005/Atom">
<title type="text">Knock knock</title>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<p>Who's there?</p>
<p>Orange.</p>
<p>Orange who?</p>
<p>Orange you glad you know how to post using curl?!? (lol!)</p>
</div>
</content>
<category scheme="http://www.blogger.com/atom/ns#" term="joke"/>
<category scheme="http://www.blogger.com/atom/ns#" term="curl"/>
</entry>With the above stored in blog_post.xml, we can now post it using the following shell script:#!/bin/sh
# Authenticate
# Requires $GDATA_PASSWORD to be set as an environment variable.
G_AUTH_TOKEN=`curl 2>/dev/null https://www.google.com/accounts/ClientLogin \
-d Email=YOUR_EMAIL_ADDRESS@example.com \
-d Passwd=$GDATA_PASSWORD \
-d accountType=GOOGLE \
-d source=curlExample \
-d service=blogger \
| grep '^Auth=' | cut -c 6-`
# Post on my blog.
curl -v --request POST -H "Content-Type: application/atom+xml" \
-H "Authorization: GoogleLogin auth=$G_AUTH_TOKEN" \
"http://www.blogger.com/feeds/YOUR_BLOGS_ID/posts/default" --data "@blog_post.xml"
When posting to Blogger, it's useful to organize your posts using using labels. When using the normal Blogger interface, this is done by adding a comma-separated list of labels to a text field at the bottom of the post. To achieve the same effect using the Blogger API, add an individual <atom:category> element for each label to your post's entry. Set the scheme to 'http://www.blogger.com/atom/ns#', and set the term to your desired label.
For example, the following code for the Zend_Gdata PHP client library would add the labels "foo" and "bar" to a post (stored in $entry):
$label1 = new Zend_Gdata_App_Extension_Category(
'foo', 'http://www.blogger.com/atom/ns#');
$label2 = new Zend_Gdata_App_Extension_Category(
'bar', 'http://www.blogger.com/atom/ns#');
$entry->setCategory(array($label1, $label2));