0

我在 facebook 上有一个应用程序,它给了我以下错误:

Fatal error: Call to a member function api() on a non-object in 
/public_html/user/fbmin.php on line 7

这是代码:

  try{             //here's line 7:
        $userdata= $facebook->api('/me');
        //request for user friends in app
        $frienddata=$facebook->api(array(
'method' => 'fql.query',
'query' => 'SELECT uid, name FROM user WHERE uid IN(SELECT uid2 FROM friend WHERE uid1 = me()) AND is_app_user = 1'
 ));}

catch (FacebookApiException $e) {
error_log($e);
$userdata = null;
$frienddata= null;
}

奇怪的是,我在另一个页面上使用了相同的代码并且一切正常,我尝试通过编写使 $facebook 全球化

GLOBAL $facebook;

在 try 语句之前,它仍然给出相同的错误,可能是什么问题?

4

1 回答 1

0

It is clear that $facebook is not yet initialized. In the other files (which work), look for a line like this:

$facebook = ...

And you need that stuff in this file, too. Or perhaps there is a dedicated fb initialization file that you need to include.

于 2012-11-12T17:57:07.887 回答