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

Post 从facebook游戏应用程序发布用户分数,post,facebook-graph-api,Post,Facebook Graph Api,我正在尝试将用户分数(整数值)发布到facebook分数。我的代码如下: <pre><?php getScores($accessToken) ?></pre> <pre><?php postScores($accessToken, 'PLAYER_ID', 34) ?></pre> <pre><?php getScores($accessToken) ?></pre> 和PHP代码

我正在尝试将用户分数(整数值)发布到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);
}