如何获取特定用户的Facebook活动源

时间:2013-01-15 13:11:23

标签: php facebook-graph-api facebook-php-sdk

是否有人知道如何获取与应用ID相关联的用户的活动供稿?

我可以使用此代码

获取与应用ID相关联的用户列表
<?php 
    require "facebook.php";
    $facebook = new Facebook(array(
        'appId'  => '',
        'secret' => '',
    )); 
    $user = $facebook->getUser();
    if ($user) {
      try {
            $result = $facebook->api(array(
            "method"    => "fql.query",
            "query"     => "SELECT uid, name, pic_square, activities FROM user
            WHERE uid IN (SELECT uid1 FROM friend WHERE uid2 = me()) and  is_app_user"
        ));
    echo "<pre>"; 
    print_r($result);
?>

输出

Array
(
    [0] => Array
        (
            [uid] => 14529121124
            [name] => Saurabh
            [pic_square] => http://profile.ak.fbcdn.net/hprofile-ak-ash4/187195_1452918224_6692287_q.jpg
            [activities] => 
        )

    [1] => Array
        (
            [uid] => 100000565666371
            [name] => Abhijeet
            [pic_square] => http://profile.ak.fbcdn.net/hprofile-ak-prn1/157718_100000289210371_1409561577_q.jpg
            [activities] => 
        )

)


现在我只想分别获取这两个用户的(用户ID:14529121124,100000565666371)的活动供稿(54975723243503)app_id。

2 个答案:

答案 0 :(得分:2)

使用图API:https://developers.facebook.com/docs/reference/api/user/

在该页面中搜索“Feed”

答案 1 :(得分:1)

您需要查询FQL stream表或Graph API供稿对象:

由于您正在使用FQL,我将使用FQL给出一个示例。我做了一些快速测试,stream表不允许您使用IN关键字从多个来源中选择流,因此您需要进行两次单独调用,首先要获取user_id s,第二个获得流。

试试这个:

$queries = array();
$i = 0;
foreach ($result as $item) {
   $queries['user_stream'.$i] =>
     "SELECT source_id, created_time, message, attachment FROM stream 
        WHERE source_id = " . $item['uid'];
   $i++;
}

$result2 = $facebook->api(array(
        "method"    => "fql.multiquery",
        "queries"     => json_encode($queries)
         ));