1

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);
}
ShawnDaGeek
  • 4,145
  • 1
  • 22
  • 39
Lance
  • 4,736
  • 16
  • 53
  • 90
  • 2
    It isn't really a good idea to post an app secret on a public site (unless it isnt your actual one). – Mythrillic Jun 17 '12 at 08:17
  • Also, i'm not clear on what your question is, it sounds like you want us to give you an [open graph protocol tutorial](https://developers.facebook.com/docs/opengraph/tutorial/) – Igy Jun 17 '12 at 08:25
  • 1
    Actually, that wouldn't hurt... :) – Lance Jun 17 '12 at 08:27
  • 1
    If you read the post, then you'd know what the question is. I need to know how to post an image and sever links to a users wall with the facebook API. I think it's pretty clear. – Lance Jun 17 '12 at 08:30

1 Answers1

4

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);
ShawnDaGeek
  • 4,145
  • 1
  • 22
  • 39
  • 1
    Wait, wait, wait... so this will let me post multiple links? Or the entire post will just be one link? – Lance Jun 17 '12 at 13:19
  • in the description, the links i added above will be rendered by facebook as a links of their own. I can test this if you give me about half an hour, or just do a quick test, and let me know. – ShawnDaGeek Jun 17 '12 at 13:22
  • 1
    Yes, half an hour is perfectly fine with me. Because, I need to have multiple links. I know that facebook will render them as links, but I want them to function like anchor tags whereby the href isn't display, but rather the text inside of the Text to display is actually displayed. – Lance Jun 17 '12 at 13:25
  • https://www.facebook.com/shawnsspace/posts/10150981633289577 urls are no longer rendered, stand by for new solution. – ShawnDaGeek Jun 17 '12 at 13:39
  • k i added in a js solution with properties array for links, did not have time to write and test in php. – ShawnDaGeek Jun 17 '12 at 13:46
  • 1
    Okay. Do you have a sample wall post that was generated from this function? – Lance Jun 17 '12 at 14:19
  • the js will invoke a dialog for the post so you will need to make a button or link if you use. or just add the properties array to curl options. – ShawnDaGeek Jun 17 '12 at 14:42
  • 1
    Yeah, I noticed that. So, theoretically, I could use php's curl_exec function to get the same results via server side instead of client side? – Lance Jun 17 '12 at 14:45
  • I believe that is correct, i do not know how to write the options into the array for cURL though, so if you could, if you get php working with the properties tag, will you post that solution for reference please. – ShawnDaGeek Jun 17 '12 at 15:18
  • 1
    Hmmm. Hate to keep bugging you. But, this function really is hit or miss. Sometimes, when I click on the element with the id that's supposed to trigger the function, it'll work. Other times, it wont... – Lance Jun 18 '12 at 03:44
  • No it is fine i am here to help, Are you loading the js sdk ansync? What browsers is it failing in? – ShawnDaGeek Jun 18 '12 at 16:59
  • 1
    I eventually got it to work with the php sdk. Although, I think the "properties" and "actions" attributes are in different in the php sdk than they are in the FB.ui – Lance Jun 18 '12 at 17:10
  • I tested and edited in a php sample with array for properties if you wish to compare code. – ShawnDaGeek Jun 18 '12 at 18:05
  • 1
    @ShawnECarter, can you help me to change "Bob shared a link via testApp" to "Bob do_something via testApp". – Mansoorkhan Cherupuzha Oct 11 '12 at 05:49
  • 1
    @MansoorkhanCherupuzha you will need to use Facebook's actions for that... http://developers.facebook.com/docs/opengraph/define-actions/ – ShawnDaGeek Oct 11 '12 at 21:01
  • 1
    @ShawnECarter, thank you. I've created an app, but only testers or developers can access this app. How can we make the app accessible to all the Facebook users. Error response is like this: The action type {name-space}:{action} does not exist or is not approved, so app {app_id} can only publish to administrators, developers, and testers of the app. User {user_id} is not one of those roles." type: "OAuthException" – Mansoorkhan Cherupuzha Oct 12 '12 at 12:24
  • 1
    first you will need to create 5 action posts to an admin account, then submit the action for approval by facebook. i do believe the app will need to be made public for submission. – ShawnDaGeek Oct 12 '12 at 21:52
  • @ShawnECarter, I already made "Sandbox Mode: Diabled", hence it is public right? Shall i need to change any other settings? App Detail Page Status: Live App Center Listing Status: Unlisted – Mansoorkhan Cherupuzha Oct 17 '12 at 06:53
  • 1
    There should be no reason to change anything else, do your test admin posts for the actions and submit them to facebook. They will review the submission, and test it. – ShawnDaGeek Oct 17 '12 at 19:39
  • can I set Height and Width of 'picture'? – Chirag Khatsuriya Dec 10 '15 at 07:21