使用图形API将内容发布到FB

时间:2012-06-17 07:45:13

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

好,

所以,我现在已经开始使用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);
}

1 个答案:

答案 0 :(得分:4)

如果您有权以用户身份发帖。上述方法调用操作,链接和附件无法以您需要的方式添加到操作中。

  

请参阅用户帖子连接。

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

具有属性功能的js sdk feed帖子

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 feed帖子

$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 feed post with properties array。

$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);