Help...Call to a member function on a non-object
10-01-2010, 07:09 PM
|
Help...Call to a member function on a non-object
|
Posts: 6
Name: cleto ramosotero
|
I'm having a hell of a time trying to figure this out. I'm trying to post labels to a blog using the gdata api. I keep getting this error:
Quote:
|
Fatal error: Call to a member function newCategory() on a non-object in C:\wamp\www\wordpress\wp-content\plugins\gdatablogger.php on line 121
|
I've tried a bunch of different things but nothing works. I'm assume the object is non-existent but my question is how do i go about creating it? The is_publishable($post_id) function is where the $tags should come from.
the problem line is
PHP Code:
$label = $gdClient->newCategory($tags, 'http://www.blogger.com/atom/ns#');
Here is most of the code
PHP Code:
define ("GDATA_ARRAY", 1); define ("GDATA_STRING", 2);
class gdata { private $blogID; // blogid from blogger.com private $email; private $password; private $categories_to_publish; // id of categories to publish private $tags_to_publish; private $timezone_offset; private $meta_key = "gdataId"; public $gdClient;
private function load_options() { foreach ($this->get_options() as $option) { switch ($option->type) { case GDATA_STRING: $this->{$option->class_var} = get_option( $option->db_var ); break; case GDATA_ARRAY: $this->{$option->class_var} = split(",", get_option( $option->db_var )); break; } } } public static function get_options() { return array ( new gdata_option("Gmail email address:", "email", GDATA_STRING), new gdata_option("Gmail password:", "password", GDATA_STRING, "This will be stored in the wordpress options table"), new gdata_option("blogger.com blog ID:", "blogID", GDATA_STRING, "Your blog id. Can be found by looking at the create post link on your blogger.com blog, it will look like: ?blogID=[number]"), new gdata_option("Categories to publish:", "categories_to_publish", GDATA_ARRAY, "Comma seprated list of Category id numbers - see: Manage->Categories"), new gdata_option("Tags to publish:", "tags_to_publish", GDATA_ARRAY, "Comma seprated list of tag id numbers - see: Manage->Tags"), new gdata_option("Timezone Offset:", "timezone_offset", GDATA_STRING, "Offset which will be applied to the date of posts when posting to blogger.com") ); } public function __construct() { $this->load_options(); }
public function authenticate() { if ($this->gdClient) return; $client = Zend_Gdata_ClientLogin::getHttpClient($this->email, $this->password, 'blogger'); $this->gdClient = new Zend_Gdata($client); }
function publish_remote($post_id) { $post = get_post($post_id); $remost_post_id = get_post_meta($post_id, $this->meta_key, true); $content = $this->format_content($post->post_content); $this->authenticate(); if (empty($remost_post_id)) { $remost_post_id = $this->gdatacreatePost($post->post_title, $content, $post->post_date); add_post_meta($post_id, $this->meta_key, $remost_post_id, true); } else { $this->updatePost($remost_post_id,$post->post_title, $content, $post->post_date); } } function format_date($date) { $datetime = date_create ($date); $datetime->modify($this->timezone_offset); return $datetime->format("c"); // needs to be in format: 2008-07-31T04:58:00.001-07:00 (ISO 8601 date) } function is_publishable($post_id) { $categories = wp_get_post_categories($post_id); if (count(array_intersect($this->categories_to_publish, $categories)) > 0) return true; $tags = wp_get_post_tags($post_id); foreach ($tags as $tag) { if (array_search($tag->term_id, $this->tags_to_publish)) return true; } return false; }
private function format_content($content) { // format the contents the same way wordpress does by default. $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); return $content; }
public function gdatacreatePost($title, $content, $published, $isDraft=False) { // We're using the magic factory method to create a Zend_Gdata_Entry. // http://framework.zend.com/manual/en/zend.gdata.html#zend.gdata.introdduction.magicfactory $entry = $this->gdClient->newEntry(); $entry->title = $this->gdClient->newTitle(trim($title)); $entry->content = $this->gdClient->newContent(trim($content)); $entry->published = $this->gdClient->newPublished($this->format_date($published)); $label = $gdClient->newCategory($tags, 'http://www.blogger.com/atom/ns#'); $entry->setCategory(array(0 => $label)); $entry->content->setType('text'); $uri = "http://www.blogger.com/feeds/" . $this->blogID . "/posts/default";
if ($isDraft) { $control = $this->gdClient->newControl(); $draft = $this->gdClient->newDraft('yes'); $control->setDraft($draft); $entry->control = $control; }
$createdPost = $this->gdClient->insertEntry($entry, $uri); $idText = split('-', $createdPost->id->text); $postID = $idText[2]; return $postID; }
class gdata_option { var $db_var, $class_var, $display_name, $type, $comment;
function __construct($display, $class_var, $type, $comment = "" ) { $this->db_var = "gdata_".$class_var; $this->class_var = $class_var; $this->type = $type; $this->display_name = $display; $this->comment = $comment; } }
function gdata_publish($post_id) { require_once 'Zend/Loader.php'; Zend_Loader::loadClass('Zend_Gdata'); Zend_Loader::loadClass('Zend_Gdata_Query'); Zend_Loader::loadClass('Zend_Gdata_ClientLogin'); $gdata = new gdata(); if ($gdata->is_publishable($post_id)) $gdata->publish_remote($post_id);
}
I know i'm in over my head since i'm really new to php, but i really want to figure this out. Any help is greatly appreciated.
|
|
|
|
10-01-2010, 07:17 PM
|
Re: Help...Call to a member function on a non-object
|
Posts: 366
Name: Steve
Location: Miami, FL, Earth
|
PHP Code:
$label = new gdata(); $label = $gdClient->newCategory($tags, 'http://www.blogger.com/atom/ns#');
</span></span></span>
__________________
- Steve
President, Please login or register to view this content. Registration is FREE
|
|
|
|
10-01-2010, 08:31 PM
|
Re: Help...Call to a member function on a non-object
|
Posts: 6
Name: cleto ramosotero
|
Thanks smoseley but, I still get the same error  . Could it have something to do with the fact that in this line gdClient has a "$" in front of it
PHP Code:
$label = $gdClient->newCategory($tags, 'http://www.blogger.com/atom/ns#');
whereas all the others do not?
PHP Code:
$entry = $this->gdClient->newEntry(); $entry->title = $this->gdClient->newTitle(trim($title)); $entry->content = $this->gdClient->newContent(trim($content)); $entry->published = $this->gdClient->newPublished($this->format_date($published));
The funny thing is it works in this code taken from the gdata site
PHP Code:
//Loading the Zend Framework require_once'Zend/Loader.php'; Zend_Loader::loadClass('Zend_Gdata'); Zend_Loader::loadClass('Zend_Gdata_Query'); Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
//Authenitication $client = Zend_Gdata_ClientLogin::getHttpClient($user,$pass,'blogger'); $gdClient = new Zend_Gdata($client);
//Initialize Zend Client $entry = $gdClient->newEntry(); $entry->title=$gdClient->newTitle(trim($judul_posting)); $entry->content=$gdClient->newContent(trim($isi_posting)); $label = $gdClient->newCategory($thetags, 'http://www.blogger.com/atom/ns#'); $entry->setCategory(array(0 => $label)); $entry->content->setType('html'); $uri = "http://www.blogger.com/feeds/".$id_blog."/posts/default"; $createdPost=$gdClient->insertEntry($entry,$uri); $idText = explode('-',$createdPost->id->text); $postID = $idText[2];
but when i add it to mine i get the error.
|
|
|
|
10-02-2010, 01:45 AM
|
Re: Help...Call to a member function on a non-object
|
Posts: 366
Name: Steve
Location: Miami, FL, Earth
|
Sorry, my bad... I screwed up my suggestion... should be:
PHP Code:
$gdClient = new gdata(); $label = $gdClient->newCategory($tags, 'http://www.blogger.com/atom/ns#');
__________________
- Steve
President, Please login or register to view this content. Registration is FREE
|
|
|
|
10-02-2010, 02:44 AM
|
Re: Help...Call to a member function on a non-object
|
Posts: 6
Name: cleto ramosotero
|
now i get this error
PHP Code:
Fatal error: Call to undefined method gdata::newCategory() in C:\wamp\www\wordpress\wp-content\plugins\gdatablogger.php on line 122
this is how I inserted your code
PHP Code:
//http://framework.zend.com/manual/en/zend.gdata.html#zend.gdata.introdduction.magicfactory $entry = $this->gdClient->newEntry(); $entry->title = $this->gdClient->newTitle(trim($title)); $entry->content = $this->gdClient->newContent(trim($content)); $entry->published = $this->gdClient->newPublished($this->format_date($published)); $gdClient = new gdata(); $label = $gdClient->newCategory($tags, 'http://www.blogger.com/atom/ns#'); $entry->setCategory(array(0 => $label)); $entry->content->setType('text'); $uri = "http://www.blogger.com/feeds/" . $this->blogID . "/posts/default";
Also I'm wondering if the $tags variable should be $tags_to_publish instead 
|
|
|
|
10-02-2010, 08:17 AM
|
Re: Help...Call to a member function on a non-object
|
Posts: 366
Name: Steve
Location: Miami, FL, Earth
|
Well there's a reason for that... that method doesn't exist in that class. Are you sure you're referencing the right class / scrpt?
__________________
- Steve
President, Please login or register to view this content. Registration is FREE
|
|
|
|
10-02-2010, 04:59 PM
|
Re: Help...Call to a member function on a non-object
|
Posts: 6
Name: cleto ramosotero
|
Thanks for all your help smoseley, I would have to say no to your last question. I tried to get an answer from the blogger dev team and they wouldn't even respond to my questions.
This is the issue, this piece of the code is supposed to contain the tags/labels
PHP Code:
function is_publishable($post_id) { $categories = wp_get_post_categories($post_id); if (count(array_intersect($this->categories_to_publish, $categories)) > 0) return true; $tags = wp_get_post_tags($post_id); foreach ($tags as $tag) { if (array_search($tag->term_id, $this->tags_to_publish)) return true; } return false; }
the problem is $tags is always empty and doesn't output anything. After much searching i found out that this is the code that will post the tags/labels
PHP Code:
$label = $gdClient->newCategory('some text here', 'http://www.blogger.com/atom/ns#'); $entry->setCategory(array(0 => $label));
so I just cut and paste and thought it would work...wrong!
How would i go about creating the method in the class without destroying the rest of the code?
|
|
|
|
10-03-2010, 09:51 PM
|
Re: Help...Call to a member function on a non-object
|
Posts: 366
Name: Steve
Location: Miami, FL, Earth
|
You can't just create the method. You're using the wrong class. You have to find the proper class or it won't function properly... It's probably called "gdData"
__________________
- Steve
President, Please login or register to view this content. Registration is FREE
|
|
|
|
10-03-2010, 09:57 PM
|
Re: Help...Call to a member function on a non-object
|
Posts: 366
Name: Steve
Location: Miami, FL, Earth
|
Here's the download you need:
http://framework.zend.com/download/gdata
This requires Zend to run properly. Are you using the Zend framework?
__________________
- Steve
President, Please login or register to view this content. Registration is FREE
|
|
|
|
10-04-2010, 04:56 PM
|
Re: Help...Call to a member function on a non-object
|
Posts: 6
Name: cleto ramosotero
|
Yes I have been using the Zend framework. I did do some more research and i've almost got it!
This works
PHP Code:
$label = new Zend_Gdata_App_Extension_Category('text here', 'http://www.blogger.com/atom/ns#');
Now I just need to replace 'text here' with the value in $tags,
PHP Code:
$label = new Zend_Gdata_App_Extension_Category($tags, 'http://www.blogger.com/atom/ns#');
But this gives me an exception
Quote:
|
Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with message 'Expected response code 200, got 400 [Line 1, Column 111, element atom:category] Category must have a 'term' attribute
|
Last edited by cletox; 10-04-2010 at 05:00 PM..
|
|
|
|
|
« Reply to Help...Call to a member function on a non-object
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|