Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Posted at www.w3tools.info
- How to post to blogger using PHP with labels/categories/tags using gData api ?
- */
- function createPublishedPost($title, $content,$tags){
- /* DEFINE THESE */
- $user = 'BLOGGER_USERNAME';
- $pass = 'BLOGGER_PASS';
- $blogID = 'YOUR_BLOG_ID';
- $service = 'blogger';
- require_once'Zend/Loader.php';
- Zend_Loader::loadClass('Zend_Gdata');
- Zend_Loader::loadClass('Zend_Gdata_Query');
- Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
- $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service, null,
- Zend_Gdata_ClientLogin::DEFAULT_SOURCE, null, null,
- Zend_Gdata_ClientLogin::CLIENTLOGIN_URI, 'GOOGLE');
- $gdClient = new Zend_Gdata($client);
- $uri = 'http://www.blogger.com/feeds/' . $blogID . '/posts/default';
- $entry = $gdClient->newEntry();
- $entry->title = $gdClient->newTitle($title);
- $entry->content = $gdClient->newContent($content);
- $entry->content->setType('html');
- $tags = explode(",",$tags);
- if(is_array($tags)){
- $labels = array();
- foreach($tags as $tag){
- $labels[] = $gdClient->newCategory(trim($tag), 'http://www.blogger.com/atom/ns#');
- }
- /* Adding tags to post */
- $entry->setCategory($labels);
- }
- $createdPost = $gdClient->insertEntry($entry, $uri);
- $idText = split('-', $createdPost->id->text);
- $newPostID = $idText[2];
- return $newPostID;
- }
- /* USAGE OF THIS FUNCTION */
- createPublishedPost("Sample post title","I'm an a post the demonstrates usage of gdata api to publish articles to a blogspot blog.","sampletag1,sampletag2");
- // tags must be passed to function as comma separated values.
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement