douzhe2981 2013-02-28 06:01
浏览 47
已采纳

如何使用Graph API拉取用户的Facebook状态消息

I've tried to use this method using the Graph API, but it doesn't return the status messages ... Is there anyway I can pull those ? How can I also get the feeds of the Facebook pages that a user's follow .. Like for example coca cola's page .. how can I retrieve its feeds if I like it ?? answers would be appreciated !!!

$status = $facebook->api("/690196511");
  • 写回答

1条回答 默认 最新

  • dsb53973 2013-02-28 06:15
    关注

    Try this code :

    <?php
    
    $facebook_appid         = "facebook_appid";                                 // Facebook appplication id
    $facebook_secret        = "facebook_secret";                // Facebook secret id
    $facebook_pageid        = "facebook_pageid";                                // Facebook secret id
    $redirect_uri           = "https://localhost/facebook_page/events.php";   // return url to our application after facebook login ## should be SAME as in facebook application
    //$redirect_uri         = "https://localhost/facebook_page/fb_login.php";   // return url to our application after facebook login ## should be SAME as in facebook application
    $scope                  = "user_photos,email,user_birthday,user_online_presence,offline_access,manage_pages,publish_stream,user_events,friends_events"; // User permission for facebook
    
    
    $code                   = $_REQUEST["code"]?$_REQUEST["code"]:"";
    
    if(empty($code)) {
        $_SESSION['state']  = time(); // CSRF protection
        $dialog_url         = "https://www.facebook.com/dialog/oauth?client_id=". $facebook_appid . "&redirect_uri=" . urlencode($redirect_uri) . "&state=". $_SESSION['state'] . "&scope=".$scope;
        header("location:".$dialog_url);
    }
    
    if($_SESSION['state'] && ($_SESSION['state'] == $_REQUEST['state'])) {
        $token_url          = "https://graph.facebook.com/oauth/access_token?". "client_id=" . $facebook_appid . "&redirect_uri=" . urlencode($redirect_uri). "&client_secret=" . $facebook_secret . "&code=" . $code;
        $response           = @file_get_contents($token_url);
    
        $params             = null;
        parse_str($response, $params);
    
        $account_url        = "https://graph.facebook.com/".$facebook_pageid."?fields=access_token&access_token=".$params['access_token'];
        $resp               = @file_get_contents($account_url);
    
        $dt                 =   json_decode($resp);
    
    
        echo $dt->access_token;
        echo "<br>";
        echo $dt->id;
    
        $offer_url        = "https://graph.facebook.com/".$dt->id."/feed?access_token=".$dt->access_token;
        $off                = @file_get_contents($offer_url);
        $dto                = json_decode($off);
    
        echo "<pre>";
        print_r($dto);
    
    
    }
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置