Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't publish a high score to player's timeline on Facebook

I'm developing a PHP game and would like to post players highscores to their own facebook wall /timeline.

I've set up a Facebook App and the PHP code I'm using to POST the score is (as provided by Facebook itself):

<?php
 require 'facebook-sdk/facebook.php';

 $app_id = MY_APP_ID;
 $app_secret = MY_APP_SECRET;
 $score = 1500;  // this is gonna be passed someway...

 $facebook = new Facebook(array(
   'appId'  => $app_id,
   'secret' => $app_secret,
 ));

 $user = MY_USER_ID;  // to be replaced with a call to $facebook->getUser()

 $app_access_token = get_app_access_token($app_id, $app_secret);
 $facebook->setAccessToken($app_access_token);
 $response = $facebook->api('/' . $user . '/scores', 'post', array(
   'score' => $score,
 ));
 print($response);

 // Helper function to get an APP ACCESS TOKEN
 function get_app_access_token($app_id, $app_secret) {
   $token_url = 'https://graph.facebook.com/oauth/access_token?'
     . 'client_id=' . $app_id
     . '&client_secret=' . $app_secret
     . '&grant_type=client_credentials';

   $token_response =file_get_contents($token_url);
   $params = null;
   parse_str($token_response, $params);
   return  $params['access_token'];
 }
?>

Of course there is a login and install section which I have omitted, asking the user to login and grant 'publish_stream' and 'publish_actions' privileges to the app.

This is working with success, the response variable outputs 1. I can see the posted score using the Facebook Graph API Explorer so I assume everything is really working fine and smooth.

The problem is that I am not able to see the supposedly posted user-story anywhere on Facebook. Reading the documentation it seems to me that a user story has to be automatically published when one saves a score. As an example, have a look here or here.

Does anyone solved this problem already? Do you see something that I might have missing? Can you please point me at the right direction to solve this issue?

Any help will be highly appreciated.

like image 437
HobieCat Avatar asked Jun 04 '12 15:06

HobieCat


People also ask

Why can't I post on people's timelines?

Find the “Timeline and Tagging” section and click the “Edit Settings” link. In the pop-up window that appears, look at the first setting—the one labeled “Who can post on your timeline.” Is it set to “No One”? If so, that's the culprit.

Why does Facebook say failed to publish?

If you are getting this error, then issue most likely is that your Facebook page access token does not have enough permission to publish content. Sometimes, your posts are published, but few times they are failed.

What is limit the Audience for old posts on your timeline?

Tap in the top right of Facebook. Scroll down and tap Settings. Scroll down to Audience and Visibility and tap Posts. Tap Limit who can see past posts.


2 Answers

You write

Reading the documentation it seems to me that a user story has to be automatically published when one saves a score.

Scores are not automatically published. They are only published under certain conditions, namely when a user:

  • gets a new high score ("High score story").
  • pass another friend's score("Passing story").

In your code you post the score 1,500 everytime. After the first time you post it, when you post it again repeatedly for testing, your post request will be successful but the score will not be published again since it is not a new high.

Sources:
Facebook Developers: Games Tutorial.
Facebook Developers Developer Blog: Games Update: Expanding distribution for Scores and Achievements

like image 63
onosendai Avatar answered Oct 21 '22 09:10

onosendai


Try look at this

https://github.com/fbsamples/CriticalMass/tree/master/web/criticalmass

Hope will be a useful

like image 40
CReaTuS Avatar answered Oct 21 '22 07:10

CReaTuS