Reputation: 119
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.
Upvotes: 10
Views: 3157
Reputation: 28480
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:
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
Upvotes: 4
Reputation: 43816
If your problem is 'When I successfully post a score to the API, it doesn't necessarily create a story in News Feed or on Timeline' this isn't a problem - this is how the scores API works.
Scores are a lightweight sharing option, and aren't always shown individually - i rarely see 'User got score X' stories on Facebook, but see 'X beat Y's Score in Z' and 'X got a new high score' fairly often - There's also a Timeline unit on a user's profile showing a summary of gaming activity and the scores data is shown there.
Just keep posting to /[user]/scores when the user gets a new high score and let Facebook take care of the distribution
Upvotes: 1
Reputation: 985
I think i've found the issue for you.
https://developers.facebook.com/docs/opengraphprotocol/#types
See the statement:
Pages of type article or video do not have publishing rights, and will not show up on user's profiles because they are not real world objects.
Upvotes: -2
Reputation: 5809
You can create a post on an application's profile page by issuing an HTTP POST request to APP_ID/feed (not PROFILE_ID/posts) with the publish_stream permissions.
More Details : TechNew.In
Upvotes: 1
Reputation: 2585
Try look at this
https://github.com/fbsamples/CriticalMass/tree/master/web/criticalmass
Hope will be a useful
Upvotes: 2
Reputation: 985
I read something recently that FB has stopped allowing Api posts to timelines. It will still show up in the news feed but just not on their wall anymore.
Upvotes: 0