从Facebook游戏应用程序发布用户分数

时间:2011-10-13 08:11:06

标签: post facebook-graph-api

我试图将用户分数(整数值)发布到Facebook分数。我的代码如下:

<pre><?php getScores($accessToken) ?></pre>
<pre><?php postScores($accessToken, 'PLAYER_ID', 34) ?></pre>
<pre><?php getScores($accessToken) ?></pre>

和PHP代码:

<?php
function getScores($accessToken) {
    $fbCurl = curl_init();
    curl_setopt($fbCurl, CURLOPT_URL, 'https://graph.facebook.com/APPLICATION_ID/scores&access_token=' . $accessToken);
    curl_setopt($fbCurl, CURLOPT_RETURNTRANSFER, 1);
    $scores = curl_exec($fbCurl);
    curl_close($fbCurl);
    echo '<h1>Scores</h1><pre>';
    var_dump(json_decode($scores));
    echo '</pre>';
}

function postScores($accessToken, $uid = 'PLAYER_ID', $score = 23) {
    $fbCurl = curl_init();
    curl_setopt($fbCurl, CURLOPT_URL, sprintf('https://graph.facebook.com/%s/scores&access_token=' . $accessToken, $uid, $score));
    curl_setopt($fbCurl, CURLOPT_RETURNTRANSFER, 0);
    $data = array('score' => $score);
    curl_setopt($fbCurl, CURLOPT_POST, true);
curl_setopt($fbCurl, CURLOPT_POSTFIELDS, $data);
    curl_exec($fbCurl);
    curl_close($fbCurl);
}

发布后,该用户的得分值仍为0.我做错了吗?

1 个答案:

答案 0 :(得分:0)

您是否将申请注册为游戏?有关更多设置和配置信息,请参阅https://developers.facebook.com/docs/score/