Take the 2-minute tour ×

I am getting the following error with some code that I am using. The error is

[Mon Jun 27 16:44:04 2011] [error] [client] PHP Fatal error: Call to a member function api() on a non-object in /public_html/users/fbmain.php on line 89

The code I am using worked ok before I made it into a function. Line 89 begins with $statusUpdate.

function post_basic_status($msg){
    try {
        $statusUpdate = $facebook->api("/$user/feed", 'post', array('message'=> $msg));
    } catch (FacebookApiException $e) {

From looking online I cannot find any solution to this. IS there anything glaringly wrong with this

share|improve this question

3 Answers 3

up vote 0 down vote accepted

I've had the same issue... until your post about calling the api from a function. It turns our that Facebook API doesn't like to be used in a function. It needs to be called on page load.

share|improve this answer
Yeah worked that out in the end, should have updated the post. Thanks –  Shane Jones Aug 16 '11 at 15:28

I had the same problem and was scratching my head until I read this post... the problem is that $facebook is declared outside the function and is being referenced inside the function but is not recognized.

You either need to pass the $facebook handle in as a parameter OR add the line GLOBAL $facebook; at the top of the function.

share|improve this answer

add the line GLOBAL $facebook; at the top of the function. it worked for me :)

share|improve this answer

Your Answer


