12.23.2011

Posting to Blogger using PHP Zend Framework

Posting to Blogger using PHP Zend Framework

Here is a simple code for posting blog to blogger via PHP Zend Framework

  1. <?php
  2. require_once 'Zend/Loader.php';
  3. Zend_Loader::loadClass('Zend_Gdata');
  4. Zend_Loader::loadClass('Zend_Gdata_Query');
  5. Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
  6. $user = 'name@example.com';
  7. $pass = 'password';
  8. $service = 'blogger';
  9. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service, null,
  10.         Zend_Gdata_ClientLogin::DEFAULT_SOURCE, null, null,
  11.         Zend_Gdata_ClientLogin::CLIENTLOGIN_URI, 'GOOGLE');
  12.        
  13. $gdClient = new Zend_Gdata($client);
  14. $blogID = 'your blog id'; // like 98744313216546562
  15. $title='Hello, world!',
  16. $content='I am blogging on the internet.'
  17. $uri = 'http://www.blogger.com/feeds/' . $blogID . '/posts/default';
  18. $entry = $gdClient->newEntry();
  19. $entry->title = $gdClient->newTitle($title);
  20. $entry->content = $gdClient->newContent($content);
  21. $entry->content->setType('text');
  22. $createdPost = $gdClient->insertEntry($entry, $uri);
  23. $idText = split('-', $createdPost->id->text);
  24. $newPostID = $idText[2];
  25. echo $newPostID;
  26. ?>

No comments:

Post a Comment