dongtuan1594 2011-05-07 13:21
浏览 46
已采纳

让Facebook PHP SDK在我的应用程序上运行的问题

I was making a facebook application in which i have to show news feeds of the user who is using it. I am using graph API to do this. The problem is that its not getting me feeds. I used it to show friends like this:

$friends = $facebook->api('/me/friends');

and it is working fine.

For news feeds i use this:

$feeds   = $facebook->api('/me/home');

it shows me an error:

Fatal error: Uncaught IDInvalidException: Invalid id: 0 thrown in 
/home/content/58/6774358/html/test/src/facebook.php on line 560

when i try to get Profile feed (Wall) by using this:

$feeds   = $facebook->api('/me/feed');

it shows me an empty array.

These API calls are showing me results in the graph API page but don't know why not working in my application.Can any one help me please.. My full code is as follows

require_once 'src/facebook.php';

// Create our Application instance. $facebook = new Facebook(array( 'appId' => 'xxxxx', 'secret' => 'xxxxx', 'cookie' => true, ));

$session = $facebook->getSession();
    $fbme = null;
// Session based graph API call.
if (!empty($session)){
    $fbme = $facebook->api('/me');
}
if ($fbme) {
     $logoutUrl = $facebook->getLogoutUrl();
     echo '<a href="'.$logoutUrl.'">Logout</a>';
}else{
    $loginUrl = $facebook->getLoginUrl();
     echo '<a href="'.$loginUrl.'">Logout</a>';
}
$friends = $facebook->api('/me/friends?access_token='.$session["access_token"]);
$feeds   = $facebook->api('/me/feed?access_token='.$session["access_token"]); 
print('<pre>Herere:');print_r($feeds);die;
  • 写回答

2条回答 默认 最新

  • dongren7374 2011-05-07 13:28
    关注

    Did you ask for the read_stream permission during authentication?

    What type of Authentication / "Allow" process did you go through?

    JavaScript SDK? Facebook PHP SDK? XFBML Login Button?

    EDIT- Here are helpful link that will get you started up:

    Facebook PHP SDK

    Authentication Process

    Building Apps on Facebook.com

    These are all official docs in Facebook and github.


    EDIT: Follow this step by step:

    From your original code, look for:

    $loginUrl = $facebook->getLoginUrl();
    

    Change it to:

    $loginUrl = $facebook->getLoginUrl(array('req_perms'=>'read_stream'));
    

    Uninstall your application first from your account:

    http://www.facebook.com/settings/?tab=applications
    

    Then try it again to show new Allow pop-up


    EDIT:

    It's also about the arrangement of code in the if statements. Use this code:

    <?php
    require_once 'src/facebook.php';
    $session = $facebook->getSession();
    $fbme = null;
    
    if($session){
        $fbme = $facebook->api('/me');
        $friends = $facebook->api('/me/friends');
        $feeds = $facebook->api('/me/feed'); 
        $logoutUrl = $facebook->getLogoutUrl();
        echo '<a href="'.$logoutUrl.'">Logout</a>';
        echo "<pre>".print_r($feeds,TRUE)."</pre>";
    }else{
        $loginUrl = $facebook->getLoginUrl(array('req_perms'=>'read_stream','canvas'=>1,'fbconnect'=>0));
        echo '<script> top.location.href="'.$loginUrl.'"; </script>>';
    }
    

    Uninstall your app again from

    http://www.facebook.com/settings/?tab=applications
    

    and re-open the application

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题