Lance
Lance

Reputation: 4820

PHP post custom app action to timeline

I want my site to have better fb integration than it currently does. As of right now, I use the following code to post a message/link to a given user's timeline.

$attachment = array('message' => 'Predicted the '.ucwords($winning_team_short).' to beat the '.ucwords($losing_team_short).' on '.ordSuffix($new_date_format).'',
            'caption' => 'Sportannica - Online Sports Encyclopedia',
            'name' => 'How will your predictions pan out?',
            'link' => 'http://www.sportannica.com/games/'.$league.'/'.$game.'/predictions',
            'description' => ''.ucwords($winning_team_short).' ('.$winning_score.')  '.ucwords($losing_team_short).' ('.$losing_score.')',
            'picture' => 'http://www.sportannica.com'.$path.''.$winning_team.'.png'
        );

        $facebook->api('/me/feed/', 'post', $attachment);

I want a better method though... one that posts a message to a user's timeline much like the way an app like spotify does.

When I go to the open graph dashboard, I have defined several custom action and object. One action is to "predict". I want to make it so that the message reads "".$fb_user_name." has predicted the ".$winning_team." to beat the ".$losing_team." on ".$game_date."";

I'm relatively new to the fb api, so I'm a bit lost when it comes to this material. I do know that spotify's method uses custom actions so I know that I'm on the right path. Could anyone post some sample php code for their method of posting a message that utilizes custom actions and objects to a user's timeline?

Thanks,

Lance

Upvotes: 1

Views: 1313

Answers (1)

ShawnDaGeek
ShawnDaGeek

Reputation: 4150

Example:

Using php sdk 3.1.1 / in a batch query, other queries removed.

   $queries = array(
        array('method' => 'POST', 'relative_url' => '/me/anotherfeed:view?feed=http://anotherfeed.com/?fbid='.$thepage[id].'')
        // any other api calls needed, this is a batch request for performance.
   );
    try {
 $postResponseA = $facebook->api('?batch='.json_encode($queries), 'POST');
    } catch (FacebookApiException $e) {
  //echo 'AF error: '.$e.'';
  }
  $actions=json_decode($postResponseA[0][body], true);

The post above is broken in to 4 part

Namespace anotherfeed:

Action view?

Object feed

URL http://anotherfeed.com/?fbid='.$thepage[id].'

This produces "User Viewed Whatever Feed on Another Feed"


The action depends on OG Meta tags in the head of the page to fill the action post.

Example Tags:

<meta property="og:title" content="SecurityNewsDaily" />    
<meta property="og:description" content="SecurityNewsDaily on Another Feed, Feeding on the best of Facebook, one page at a time." />
<meta property="og:type" content="anotherfeed:feed" />
<meta property="og:image" content="https://graph.facebook.com/146893188679657/picture?type=large" />
<meta property="og:site_name" content="AnotherFeed" />
<meta property="fb:app_id" content="135669679827333" />
<meta property="fb:admins" content="732484576" />
<meta property="og:url" content="http://anotherfeed.com/index.php?fbid=146893188679657" />
<meta property="og:restrictions:age" content="13+"/>

Upvotes: 1

Related Questions