Facebook App - 发布给朋友新闻Feed

时间:2012-06-28 14:31:03

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

我正在构建Facebook应用程序,我希望应用程序发布预定义的消息:

1)用户的新闻Feed(即使用该应用的任何用户)

2)如果可能,用户的朋友的新闻提要甚至他们的墙。

目前,我只使用以下代码将其发布到用户的墙上:

if(isset($_POST['mapp_message'])){
        try {
            $facebook->api('/me/feed', 'POST', array(
                'access_token' => $facebook->getAccessToken(),              
                'message' => $_POST['mapp_message'],
                'name' => "This is the title of my post",
                'description' => "This is the body of the post with lots of text in it",
                'link' => 'http://www.mysite.com',
                'picture'=>"http://lipsum.com/images/lipsum07.gif",
                'privacy' => array('value' => 'EVERYONE')               
            ));
            $sent = true;
        } catch (FacebookApiException $e) {
            //do something about it
        }
    }

注意:我刚刚发现他们的用户墙和新闻Feed之间存在差异。

我一直在谷歌上搜索几个小时,但我一直无法弄明白。所以任何帮助表示赞赏。

此致

更新

好的,我取得了一些进展。我设法将它发布在用户的朋友的墙上(即使用该应用程序的人的朋友)。代码如下:

try {
        $userData = $facebook->api('/me');

    } catch (FacebookApiException $e) {
        //do something about it
    }    

try {
            $friendsTmp = $facebook->api('/' . $userData['id'] . '/friends');
            shuffle($friendsTmp['data']);
            array_splice($friendsTmp['data'], 5);
            $friends = $friendsTmp['data'];
        } catch (FacebookApiException $e) {
            //do something about it
        }

这段代码随机选择使用该应用程序的5位朋友,并在其墙上发布代码如下:

foreach($friends as $k => $i){                                      
                $facebook->api('/'.$i['id'].'/feed', 'POST', array(
                    'access_token' => $facebook->getAccessToken(),              
                    'message' => $_POST['mapp_message'],
                    'name' => "This is the title of my post",
                    'description' => "This is the body of the post with lots of text in it",
                    'link' => 'http://www.mysite.com',
                    'picture'=>"http://lipsum.com/images/lipsum07.gif"
                    //'privacy' => array('value' => 'EVERYONE')             
                ));                                     
            }

但我仍然希望如果我可以将其发布到新闻Feed中。

0 个答案:

没有答案
相关问题