2

我正在尝试使用下面显示的 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);
4

1 回答 1

4

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

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

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

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

于 2012-07-07T09:00:02.693 回答