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

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值