dqwh1119 2012-06-17 07:45
浏览 47
已采纳

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

Okay,

So, I've been dabbling with the Graph API for a couple of days now. I know how to post a simple message to a user's wall. But, I need to post multiple links to a user's wall. And apparently, that's not possible using my previous method. I'm so lost here. What I need to so is post content to a user's wall once they have made a prediction on the my site. So, for example I need to have a post on the user's wall that reads:

<?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.''; ?>

Does anyone have any idea how I could achieve this using the graph API? I already set up custom actions and objects on FB. But, don't quite know where to go from here.

Thanks

The code that I have is as follows:

$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条回答 默认 最新

  • douyin6188 2012-06-17 13:17
    关注

    Provided you have permission to make post as user. Your method above invokes actions, links and attachments can not be added to actions in the manner you need.

    Refer to user post connection.

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

    js sdk feed post with properties function

    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'}
                    ]       
            });
            };
    

    Simple php sdk feed post

    $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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 用arduino开发esp32控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题