1

好的,

所以,我这几天一直在涉足 Graph API。我知道如何将简单的消息发布到用户的墙上。但是,我需要将多个链接发布到用户的墙上。显然,使用我以前的方法是不可能的。我在这里迷路了。一旦他们在我的网站上做出预测,我需要将内容发布到用户的墙上。因此,例如,我需要在用户的墙上发布一个帖子,内容如下:

<?php
  echo '<img src="img/teams/'.$winning_team.'.png" alt="'.$winning_team.'" /> '.$user_name.' predicted the '.$winning_team.' to beat the '.$losing_team.' on '.$game_date.''; ?>

有谁知道我如何使用图形 API 来实现这一点?我已经在 FB 上设置了自定义操作和对象。但是,完全不知道从这里去哪里。

谢谢

我拥有的代码如下:

$facebook = new Facebook(array(
    'appId' => 'appID',
    'secret' => 'secret',
    'cookie' => true
));

$access_token = $facebook->getAccessToken();
$user = $facebook->getUser();

if($user != 0) 
{
     $attachment = array(
        'access_token' => $access_token,
        'game' => 'http://www.sportannica.com',
        'away_team' => 'New York Yankees',
        'home_team' => 'New York Mets'
    );

    $opts = array(
        CURLOPT_CONNECTTIMEOUT => 10,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT => 60,
        CURLOPT_USERAGENT => 'facebook-php-3.1',
        CURLOPT_POSTFIELDS => $attachment,
        CURLOPT_URL => 'https://graph.facebook.com/me/predict-edit-add:predict'
    );

    $ch = curl_init();
    curl_setopt_array($ch, $opts);
    $result = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);
}
4

1 回答 1

4

前提是您有权以用户身份发帖。您上面的方法调用了动作,链接和附件不能以您需要的方式添加到动作中。

参考用户帖子连接。

https://developers.facebook.com/docs/reference/api/user/#posts

带有属性功能的 js sdk 提要帖子

function anotherfeedthis() {
    FB.ui({ method: 'feed', 
         message: 'Testing Message',
        caption: 'This is the Caption value.',
        name: 'Testing JS feed dialog on Antoher Feed',
        link: 'http://anotherfeed.com?ref=link',
        description: 'Testing property links, and action links via Feed Dialog Javascript SDK',
        //picture: 'https://shawnsspace.com/ShawnsSpace.toon.nocolor..png',
        properties: [
        { text: 'Link Test 1', href: 'http://anotherfeed.com?ref=1'},
         { text: 'Link Test 2', href: 'http://anotherfeed.com?ref=2'},
                ],
        actions: [
        { name: 'Shawn', link: 'http://anotherfeed.com'}
                ]       
        });
        };

简单的 php sdk 提要帖子

$facebook->api('/me/feed', 'post', array(
'message' => message,
'name' => 'name or title',
'description' => 'here goes description and links http:anotherfeed.com | http://facebook.com/anotherfeed',
'caption' => 'this is caption for action link',
'picture' => 'image url',
'link' => 'action link here',
));

带有属性数组的 php sdk 提要帖子。

$build=array(
'message' => 'message',
'name' => 'name or title',
'description' => 'here goes description and links http:anotherfeed.com | http://facebook.com/anotherfeed',
'caption' => 'this is caption for action link',
'picture' => 'image url',
'link' => 'action link here',
    'properties' => array(
    array('text' => 'test link 1', 'href' => 'http://anotherfeed.com/?ref=1'),
    array('text' => 'test link 1', 'href' => 'http://anotherfeed.com/?ref=1'),
    ),
);
$facebook->api('/me/feed', 'post', $build);
于 2012-06-17T13:17:41.973 回答