Articles Directory

  • 0

How To Remote 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.  
  7. $pass = 'password';
  8. $service = 'blogger';
  9.  
  10. $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service, null,
  11.         Zend_Gdata_ClientLogin::DEFAULT_SOURCE, null, null,
  12.         Zend_Gdata_ClientLogin::CLIENTLOGIN_URI, 'GOOGLE');
  13.        
  14. $gdClient = new Zend_Gdata($client);
  15.  
  16. $blogID = 'your blog id'; // like 98744313216546562
  17.  
  18. $title='Hello, world!',
  19. $content='I am blogging on the internet.'
  20.  
  21. $uri = 'http://www.blogger.com/feeds/' . $blogID . '/posts/default';
  22. $entry = $gdClient->newEntry();
  23. $entry->title = $gdClient->newTitle($title);
  24. $entry->content = $gdClient->newContent($content);
  25. $entry->content->setType('text');
  26.  
  27. $createdPost = $gdClient->insertEntry($entry, $uri);
  28. $idText = split('-', $createdPost->id->text);
  29. $newPostID = $idText[2];
  30.  
  31. echo $newPostID;
  32.  
  33. ?>
loading...

Related posts

Related posts