【问题标题】:parse facebook user timeline using php使用 php 解析 facebook 用户时间轴
【发布时间】:2014-02-26 04:38:29
【问题描述】:

我正在使用 php 获取用户/页面 facebook 时间线的提要。到目前为止我要说的是:

<?php
    require 'src/facebook.php';
    $facebook = new Facebook(array(
      'appId'  => 'xxx',
      'secret' => 'xxx',
    ));
    $username = isset($_GET['username'])?$_GET['username']:"agptj";
    $profile = $facebook->api('/'.$username.'/posts');
?>

<br/><br/><img src="https://graph.facebook.com/<?=$username?>/picture">

<?php
    foreach( $profile['data'] as $data ){
        if($data['message']){
            echo $data['message']."<br><hr><br>";
        }else{
            echo $data['story']."<br><hr><br>";
        }
    }
?>

这适用于页面:$username = "mashable"。但是,当我尝试对配置文件执行相同操作时,它会显示 activity log 而不是状态更新。例如:$username = "agptj"

输出:

Prakash Timilsina updated his cover photo.

如何使用 php 获取配置文件的状态更新而不是活动日志?

编辑

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

使用范围read_stream 登录并寻找/statuses 作为

$profile = $facebook-&gt;api('/'.$username.'/statuses');

让我访问我自己的个人资料和朋友的个人资料状态,但不让我read random person's public updates。我该怎么做?

【问题讨论】:

  • 您是否在 read_stream 权限下尝试过?您可能希望将该 access_token 提供给 api 调用。你可以通过他们的 api explorer 快速查看:developers.facebook.com/tools/explorer
  • 您好@AtaurRahimChowdhury,请您阅读Edit
  • 如果您仍然有问题,我试图获取不是我朋友的人的公开状态,我无法使用查询中的状态通过资源管理器获取它。但通过“用户名/帖子”,我可以看到他最近发布的帖子。如果您只想要状态,您可以通过在查询中添加 status_type 来过滤掉它。这是我尝试使用的示例查询:developers.facebook.com/tools/explorer/…

标签: php facebook facebook-graph-api


【解决方案1】:

Facebook 图形 API 不允许您访问 random profile's public updates。 API 允许的最大功能,您已经掌握了

验证我的回答

  1. 打开图形浏览器:https://developers.facebook.com/tools/explorer/

  2. 点击 Get Access Token 并获取 facebook graph API 允许的每个 permissions 的令牌。 User Data PermissionsFriends Data PermissionsExtended Permissions

  3. 现在使用GET 方法,让/zuck/statuses 这是一个公共配置文件

  4. 你可以看到什么都不返回

    {"data": []}

【讨论】:

    【解决方案2】:

    未经他/她的许可,您无法阅读随机用户的帖子提要(包括他们的公开状态更新)。您需要来自具有read_stream 权限的用户的有效User Access Token 才能执行此操作。

    使用有效的访问令牌,您可以通过使用 Graph API 或在 stream 表上使用 FQL 查询来为特定用户或他/她的朋友实现此目的。您可以使用如下查询:

    SELECT post_id, message FROM stream WHERE source_id = {User_ID} LIMIT 50 
    

    或者,如果您特别关心用户或他/她朋友的状态,您可以使用status 表,例如:

    SELECT status_id, message FROM status WHERE uid = {User_ID} LIMIT 50
    

    但是,当用户状态更新和页面状态更新发布到 Facebook 时,有一种方法可以读取它们。这可以通过使用Public Feed API 来完成。但这只会包括将隐私设置为“公开”的状态更新包含在流中。此外,由于访问受限,您目前无法申请使用该 API。

    【讨论】:

      【解决方案3】:

      使用 /statuses 而不是 /posts。

      【讨论】:

        【解决方案4】:

        Prakash,很抱歉告诉您,即使此状态的隐私是公开的,您也无法访问随机用户的状态,除非您获得该用户的有效访问令牌或他的一位朋友的访问令牌.我现在这个答案与以前的一些答案具有相同的意思,但我写它是为了确认这些答案。

        Prakash 先生,我有一个问题要问您。你能提供给我们,你想要什么?也许我们会找到另一种方法。

        【讨论】:

          【解决方案5】:
          <?php
              require 'src/facebook.php';
              $facebook = new Facebook(array(
                'appId'  => 'xxx',
                'secret' => 'xxx',
              ));
              $username = isset($_GET['username'])?$_GET['username']:"agptj";
              $profile = $facebook->api('/'.$username.'/statuses');
          ?>
          
          <br/><br/><img src="https://graph.facebook.com/<?=$username?>/picture">
          
          <?php
              foreach( $profile['data'] as $data ){
                  if($data['message']){
                      echo $data['message']."<br><hr><br>";
                  }else{
                      echo $data['story']."<br><hr><br>";
                  }
              }
          ?>
          

          【讨论】:

          • eprakash.info/fb/index.php?username=agptj你可以看看那个网站,什么都没有显示
          • 我在$profile = ..;之后有print_r($profile);
          • 您确定您对 API 密钥具有适当的访问权限吗?
          • [25-Feb-2014 22:55:39] PHP Fatal error: Uncaught OAuthException: (#100) Requires user session thrown in /home/eprakash/public_html/fb/src/base_facebook.php on line 1340
          • 您需要 user_status 权限才能访问状态
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多