I'm setting up achievements for a game I'm working on. Flash sends the command to unlock the achievement, as well as the url to the achievement. On my server, I have the code that passes the display order and achievement url from Flash to Facebook. When I press the button to unlock the achievement in Flash, it unlocks successfully in my game and I can see it on the ticker. When I click the button from within the iFrame to unlock the achievement it won't unlock. Logging $result will return 1, but it will not show up in the ticker or count as unlocked.
postachievement.php
<?php
include 'src/facebook.php';
$facebook = new Facebook(array(
'appId' => '[APP_ID]',
'secret' => '[APP_SECRET]', ));
$access_token = $facebook->getAccessToken();
//$uid = $facebook->getUser();
$uid = "[Static ID for Testing]";
$achievement = $_POST['achievement'];
$achievement_URL = 'https://graph.facebook.com/' . $uid . '/achievements';
$achievement_result = https_post($achievement_URL,
'achievement=' . $achievement
. '&access_token=' . $access_token);
error_log($result);
function https_post($uri, $postdata)
{
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
Achievements.as
package Facebook
{
public class Achievements
{
public static var trophy:Achievements;
private static var achievement:String; // URL of the Achievement
public function Achievements()
{
trophy = this;
}
public static function testAchievement1():void
{
achievement = "https://(URL)/zombies/game/achievements/test6.html";
Database.data.giveAchievement(achievement);
}
public static function testAchievement2():void
{
achievement = "https://(URL)/zombies/game/achievements/test7.html";
Database.data.giveAchievement(achievement);
}
public static function testAchievement3():void
{
achievement = "https://(URL)/zombies/game/achievements/test8.html";
Database.data.giveAchievement(achievement);
}
public static function testAchievement4():void
{
achievement = "https://(URL)/zombies/game/achievements/test9.html";
Database.data.giveAchievement(achievement);
}
public static function testAchievement5():void
{
achievement = "https://(URL)/zombies/game/achievements/test10.html";
Database.data.giveAchievement(achievement);
}
}
}
Some snippets from the Database class that deal with the achievements.
Database.as
// Give Achievement
private static var achieveLoader:URLLoader = new URLLoader();
private static var achieveRequest:URLRequest = new URLRequest;
achieveRequest.url = "https://(URL)/zombies/game/postachievement.php";
// Grant Player an Achievement
public function giveAchievement(_achievement:String):void
{
var vars:URLVariables = new URLVariables();
vars.achievement = _achievement;
achieveRequest.method = URLRequestMethod.POST;
achieveRequest.data = vars;
achieveLoader = new URLLoader();
achieveLoader.dataFormat = URLLoaderDataFormat.TEXT;
achieveLoader.load(achieveRequest);
}
This is getting the Player's access token rather than the applications. I got the application's access token and statically put it into the variable. As long as the app's access token doesn't change, this will work.