发布游戏成就 - 无效令牌错误:'已指定ID'

时间:2012-07-06 19:48:03

标签: facebook api achievements

我正在尝试使用下面显示的PHP CURL代码将游戏成就发布到Facebook。

我有两个变量$non_sef_achievement$sef_achievement

使用$sef_achievement我知道我有一个invalid type game,并且game.achievements是必需的。

使用$non_sef_achievement变量,当我注册成就时,我会得到以下转储。请注意,当我发布分数时,我得到true,而当我尝试发布成绩时,我会得到另一个错误。

你能帮我找到我做错的事吗?

[string] {"error":{"message":"Invalid token: \"103032446\". An ID has already been specified.","type":"OAuthException","code":2500}} = "Register: " Tooltip

[string] true = "Post Score: " Tooltip

[string] {"error":{"message":"Invalid token: \"1000234234602\". An ID has already been specified.","type":"OAuthException","code":2500}} = "Post Achievement: " Tooltip

注意标记已被编辑。

    //Get the achievement
    $achievement_user = $this->achUser->event_user->username;
   // $achievement = 'http://apps.facebook.com/my_app/component/achievements/achievement/'.$this->achUser->ach->name.'-'.$this->achUser->ach->id;
     $non_sef_achievement = 'https://apps.facebook.com/my_app/index.php?option=com_jachievements&view=achievement&id='.$this->achUser->ach->id;
   // http://mysite.com/index.php?option=com_jachievements&view=achievement&id=1
     $sef_achievement = 'https://apps.facebook.com/my_app/achievements/achievement/'.$this->achUser->ach->id;

    //CHECK https 
    $achievement_display_order = 1;

    // Get an App Access Token
    $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);
    $app_access_token = $params['access_token'];

    $achievement_registration_URL = 'https://graph.facebook.com/'.$app_id.'/achievements';

    $ch = curl_init($achievement_registration_URL);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'achievement='.$non_sef_achievement.'&display_order='.$achievement_display_order.'&access_token='.$app_access_token);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($ch);
    curl_close($ch);

 $ach_id = $this->achUser->ach->id;

    $db =& JFactory::getDBO();
    $tableName = $db->nameQuote('jos_ja_achievements_actions');
    $achparams = $db->nameQuote('params');
    $achtype = $db->nameQuote('community_addkarmapoints');
    $sql = "SELECT $achparams FROM ".$tableName." WHERE ach_id =  $ach_id AND `type_name` = 'community_addkarmapoints'" ; 
    $db->setQuery($sql);
    $row = $db->loadRow();
    $achparam = $row['0'];
    $str = explode('"',$achparam);
    $ach_points = $str['3'];

    $score = $ach_points;

         $score_URL = 'https://graph.facebook.com/' .$fbUserId. '/scores';      
    $ch = curl_init($score_URL);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'score='.$score.'&access_token=' . $app_access_token);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($ch);
    curl_close($ch);


         POST a user achievement         
    $achievement_URL = 'https://graph.facebook.com/'.$fbUserId.'/achievements';
    $ch = curl_init($achievement_URL);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, 'achievement='.$non_sef_achievement.'&access_token=' . $app_access_token);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $result = curl_exec($ch);
    curl_close($ch);

1 个答案:

答案 0 :(得分:4)

如果您发出如下请求,可能会导致“已指定ID”

https://graph.facebook.com/[USER ID]/feed?id=[SOME OTHER ID]

在该示例中,路径中的第一个“[USER ID]”是Facebook对请求的“id”,并指定另一个ID作为参数会触发错误。

在这种情况下,最可能的原因是,如果您的成就网址在您调用API之前未正确转义的网址中有“?id =” - 请检查您的编码或更改参数的名称您在成就生成代码中使用