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