由于我是facebook游戏的新手,是否有任何第三方API用于flash游戏。实际上,我使用的是mochi highscore API,但我不想通过mochi登录。通过facebook id直接提交。让我知道任何第三方API或建议任何教程。
致敬,chandu
发布于 2012-08-31 21:34:03
在Facebook中将分数发布到高分是相当容易的,请查看以下代码。所有你需要的是当你登录用户时从facebook获得的userID,以及你在游戏中使用的分数,比如经验,积分或其他东西。
// post experience as score
$experience = 1000; // get this from your database
$contents = file_get_contents("https://graph.facebook.com/oauth/access_token?client_id=".FACEBOOK_APP_ID."&client_secret=".FACEBOOK_SECRET_KEY."&grant_type=client_credentials");
$exploded = explode("=",$contents);
$accessToken = $exploded[1];
$score_URL = 'https://graph.facebook.com/' . $userFacebookID . '/scores';
$score_result = https_post($score_URL,
'score=' . $experience
. '&access_token=' . $accessToken
);https_post函数如下所示:
function https_post($uri, $postdata)
{
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}你可以在获得脸书用户ID后把它放到你的index.php中,每次他们来看比赛时他们的分数都会被发送出去。
希望这能有所帮助。
https://stackoverflow.com/questions/12210653
复制相似问题