facebook请求阅读和user_id geting问题

时间:2012-05-08 10:48:02

标签: php javascript facebook facebook-graph-api facebook-c#-sdk

我发送我的请求

 <?php 
         $app_id = "127736900693315";

         $canvas_page = "http://apps.facebook.com/greetingz";

         $message = "Dynamic_msg";
         $data_s="Dynamic_data";


         $requests_url = "https://www.facebook.com/dialog/apprequests?app_id=" 
                . $app_id . "&redirect_uri=" . urlencode($canvas_page)
                . "&message=" . $message."&data=".$data_s;

         if (empty($_REQUEST["request_ids"])) {
            echo("<script> top.location.href='" . $requests_url . "'</script>");


         } else {

         }
?>

这个请求没问题,但是当接收者点击通知时我通过request_ids代码获取

    if(!empty($_REQUEST['request_ids'])) {

    $config = array(
        'appId' => '343704039016593',
        'secret' => '56e711bf93d4e46426aa662c8be8d5ef',
        'cookie' => true,

    );
       $facebook = new Facebook($config);
        echo  $user_id= $facebook->getUser(); //** 0 printing**
        $app_token = $facebook->getAccessToken();

            $requests = explode(',',$_REQUEST['request_ids']);
            foreach($requests as $request_id) {

        $request_content = json_decode(file_get_contents("https://graph.facebook.com/'".$request_id."_".$user_id."'?access_token=$app_token"), TRUE);
print_r($request_content);  //**nothing is printing**


$deleted = file_get_contents("https://graph.facebook.com/$request_id?access_token=$app_token&method=delete");       





            }

我的编码错误,我尝试了近7天,我在网上查了教程,其中大部分都是旧的,现在API已经更新了。我甚至无法获得user_id ...我是否需要发送我的请求OAuth Dialog?     }

1 个答案:

答案 0 :(得分:1)

这对我有用

foreach($ids as $id) {
    //you will get your data here
    $data = $facebook - > api('/'.$user.'/apprequests?'.$access_token);

    //you will delete the request here
    $delete_url = "https://graph.facebook.com/".$id."_".$user."?".$access_token."&method=delete";
    $result = file_get_contents($delete_url);
}​

希望这有帮助