Jump to content

Recommended Posts

Does anyone see what's wrong with this script?

 

<?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');


// get feed

$feed_url = "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;
   $lis4 = (string) $lis2 . '<br><a href="%s" title="%s">%s</a>',$lis3,$lis1,$lis1;
   
}


// 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()
{
  $uri = 'http://www.blogger.com/feeds/' . $blogID . '/posts/default';
  $entry = $gdClient->newEntry();
  $entry->title = $gdClient->newTitle($lis1);
  $entry->content = $gdClient->newContent($lis4);
  $entry->content->setType('html');

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

  return $newPostID; 
}

getFeed($feed_url);
createPublishedPost();




?>  

 

Your help would be greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/136273-whats-wrong/
Share on other sites

for all we know, several hundred things COULD be wrong with that script, since we have no idea what it does, what it's supposed to do, and therefore what's wrong.

 

we need some guidance.  try telling us what it should be doing, what it's doing instead, and/or any PHP errors you're being given.

Link to comment
https://forums.phpfreaks.com/topic/136273-whats-wrong/#findComment-710899
Share on other sites

sorry about that. It is first supposed to take an rss feed. Save xml tags <title>, <description>, <link> into strings. then it is supposed to login to google account. And post strings into a new blog post on blogger.

 

Everything is divided into chunks that is commented above the code. If you need more detail please list some specific code examples and I'll tell you what it supposed to do.

 

Basically when I run this script it will grab the first rss post from a specified feed then and use that data to automatically create and publish a new blog post on blogger.

Link to comment
https://forums.phpfreaks.com/topic/136273-whats-wrong/#findComment-710904
Share on other sites

sorry about that. It is first supposed to take an rss feed. Save xml tags <title>, <description>, <link> into strings. then it is supposed to login to google account. And post strings into a new blog post on blogger.

 

Everything is divided into chunks that is commented above the code. If you need more detail please list some specific code examples and I'll tell you what it supposed to do.

 

Basically when I run this script it will grab the first rss post from a specified feed then and use that data to automatically create and publish a new blog post on blogger.

 

okay, first step done: we know what it's SUPPOSED to do.  so what's actually wrong with it?  is it showing up blank?  is it just not working?  if it's not working, is it a complete failure, or does it manage some things but not others?

Link to comment
https://forums.phpfreaks.com/topic/136273-whats-wrong/#findComment-710908
Share on other sites

OK, I changed some stuff now I have this error message

 

Notice: Undefined variable: gdClient in /home/rpfcoder/public_html/autoblog.php on line 45

 

Fatal error: Call to a member function newEntry() on a non-object in /home/rpfcoder/public_html/autoblog.php on line 45

 

Please, anyone that can shed some light on this.

Link to comment
https://forums.phpfreaks.com/topic/136273-whats-wrong/#findComment-711178
Share on other sites

you're trying to call newEntry() on $gdClient from within another function, createPublishedPost(), where $gdClient will not exist.  you either need to pass $gdClient to the outer function, or you need to globalize that variable.

 

Ok I fixed that issue and a few others that came up afterward. Here is the updated 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 = "http://www.scripting.com/rss.xml";   

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




?>  



 

OK now I'm getting this error message that I don't even know where to begin.

 

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/136273-whats-wrong/#findComment-711861
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.