Facebook邀请不会被删除

时间:2011-11-26 06:19:41

标签: php facebook

我正在使用facebook功能在接受邀请后从通知和应用程序页面选项卡中删除邀请但是它给了我一个错误。

       function build_full_request_id($request_id, $user_id) {
      echo $request_id . '_' . $user_id; 
      }

    foreach ($request_ids as $request_id)
   {
    ("reqeust_id=".$request_id."<br>");
    $full_request_id = build_full_request_id($request_id, $user_id);  
   ("full_request_id=".$full_request_id."<br>");

  try {
     $delete_success = $facebook->api("/$full_request_id",'DELETE');
     if ($delete_success) {
        echo "Successfully deleted " . $full_request_id;}
     else {
       echo "Delete failed".$full_request_id;}
    }          
  catch (FacebookApiException $e) {
   "error";}
} 

这是错误,我得

中的非对象上调用成员函数api()

2 个答案:

答案 0 :(得分:0)

错误表示您的变量$facebook不是对象。在代码中找到创建$facebook的位置,并确保正确生成它。看起来应该是这样的:

$facebook = new Facebook(array(
  'appId'  => '1231231231231',
  'secret' => '12ba5212bae2617267',
));

(显然,它应该有你的appId和秘密,而不是我放在那里的垃圾。)

答案 1 :(得分:0)

哇,你的“代码”中有这么多错误我不知道它只会因非对象错误而失败。试试这个:

$facebook = new Facebook(array(
  'appId'  => '1231231231231',
  'secret' => '12ba5212bae2617267',
));


foreach ($request_ids as $request_id)   {
    $full_request_id = $request_id."_".$user_id;  

    try {
      $delete_success = $facebook->api('/'.$full_request_id, 'DELETE');
      if ($delete_success) {
          echo "Successfully deleted ".$full_request_id;
      }else{
          echo "Delete failed ".$full_request_id;
      }
    } catch(FacebookApiException $e) {
        echo $e->getMessage();
    }
}