簡體   English   中英

使用圖形API將內容發布到FB

[英]Post content to FB using graph API

好的,

所以,我現在已經開始使用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);
}

如果您有權以用戶身份發帖。 上述方法調用操作,鏈接和附件無法以您需要的方式添加到操作中。

請參閱用戶帖子連接。

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

帶有屬性功能的js sdk feed post

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM