doubinduo3364 2014-04-24 06:07
浏览 44
已采纳

如何从帐户获取Facebook状态

I'm trying to get facebook user statuses from their feed. Here is my code:

<?php
  require_once('facebook.php');

  $config = array(
    'appId' => 'my_app_id',
    'secret' => 'my_app_secret',
    'allowSignedRequest' => false
  );

  $facebook = new Facebook($config);
  $user_id = $facebook->getUser();//get user_id here...
?>
<html>
  <head></head>
  <body>

  <?php
    if($user_id) {
      try {

        $status = $facebook->api('/me/posts?limit=1');//get posts here...
        echo "The status: " . $status['message'];//print the message of posts...

      } catch(FacebookApiException $e) {
        $params = array(
        'scope' => 'email, read_stream, user_interests, user_likes, user_location, user_status',
        'redirect_uri' => 'http://localhost/facebook/index.php', // Replace with your app url
    ); //permission = read_stream, user_status
        $login_url = $facebook->getLoginUrl($params);
        echo 'Please <a href="' . $login_url . '">login.</a>';
        error_log($e->getType());
        error_log($e->getMessage());
      }   
    } else {
      $login_url = $facebook->getLoginUrl();
      echo 'Please <a href="' . $login_url . '">login.</a>';

    }

  ?>

  </body>
</html>

But the result is empty. Could anyone advise me on how to solve this problem?

Thank you so much!

  • 写回答

1条回答 默认 最新

  • dongxiequ3724 2014-04-24 06:34
    关注

    You are reading returned data in wrong way, it should be;

    $response = $facebook->api('/me/posts?limit=1');//get posts here...
    $status = null;
    foreach($response["data"] as $item) {
        $status = $item["message"];
    }
    echo "The status: " . $status;
    

    You can test your queries here for returned data format

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应