Jump to content

Recommended Posts

Hey guys I pieced together this script to try and grab the first post in an rss feed and then create and publish a new blogger post with the title and description from rss feed. Here is the code.

 

<?php  

ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
error_reporting(E_ALL);

require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_Query');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');

// Traditional instantiation
$gdClient = new Zend_Gdata();
$draft = new Zend_Gdata_App_Extension_Draft();

// Magic factory instantiation
$gdClient = new Zend_Gdata();
$draft = $gdClient->newDraft();



// get feed

$feed_url = "some rss feed url";   

function getFeed($feed_url) {  
   $content = file_get_contents($feed_url);  
   $xml = new SimpleXmlElement($content);
   $lis1 = (string) $xml->channel->item[0]->title;
   $lis2 = (string) $xml->channel->item[0]->description;
   $lis3 = (string) $xml->channel->item[0]->link;
   
   
}


// Log in to google api

$user = 'example@gmail.com';
$pass = 'password';
$service = 'blogger';

$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);

// Create Blog Post

function createPublishedPost($title = ' . $lis1 . ', $content = ' . $lis2 . ')
{
  $gdClient = new Zend_Gdata();
  $uri = 'http://www.blogger.com/post-create.g?blogID=Some Blog Id';
  $entry = $gdClient->newEntry();
  $entry->title = $gdClient->newTitle($title);
  $entry->content = $gdClient->newContent($content);
  $entry->content->setType('text');

  $createdPost = $gdClient->insertEntry($entry, $uri);
  $idText = split('-', $createdPost->id->text);
  $newPostID = $idText[2]; 

  return $newPostID; 
}

getFeed($feed_url);
createPublishedPost();




?> 

 

It's spitting out this error.

 

Fatal error: Uncaught exception 'Zend_Gdata_App_Exception' with message 'DOMDocument cannot parse XML: DOMDocument::loadXML() [<a href='function.DOMDocument-loadXML'>function.DOMDocument-loadXML</a>]: Premature end of data in tag html line 2 in Entity, line: 338' in /home/rpfcoder/public_html/Zend/Gdata/App/FeedEntryParent.php:121 Stack trace: #0 /home/rpfcoder/public_html/Zend/Gdata/App.php(853): Zend_Gdata_App_FeedEntryParent->__construct('<!DOCTYPE HTML ...') #1 /home/rpfcoder/public_html/autoblog.php(60): Zend_Gdata_App->insertEntry(Object(Zend_Gdata_Entry), 'http://www.blog...') #2 /home/rpfcoder/public_html/autoblog.php(68): createPublishedPost() #3 {main} thrown in /home/rpfcoder/public_html/Zend/Gdata/App/FeedEntryParent.php on line 121

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/136341-blogger-zend_gdata-problem/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.