Reputation: 4820
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);
}
Upvotes: 1
Views: 5788
Reputation: 4150
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
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'}
]
});
};
$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',
));
$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);
Upvotes: 4