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条)

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能