Help with script for blogger
Posted: Wed Dec 10, 2008 4:16 am
Hey everyone,
semi newbie here. I put together this script that utilizes blogger data api and zend gdata framework. It is supposed to grab the first entry in a specified rss feed and these turn this into a new blog post on blogger.com. Here is the code:
ok, and it's giving me this error message:
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
Please help guys this is driving me nuts.
semi newbie here. I put together this script that utilizes blogger data api and zend gdata framework. It is supposed to grab the first entry in a specified rss feed and these turn this into a new blog post on blogger.com. Here is the code:
Code: Select all
<?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 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();
?>
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
Please help guys this is driving me nuts.