我正在为我正在开发的游戏设置成就。Flash 发送解锁成就的命令,以及成就的 url。在我的服务器上,我有将显示顺序和成就 url 从 Flash 传递到 Facebook 的代码。当我按下按钮解锁 Flash 中的成就时,它在我的游戏中成功解锁,我可以在代码中看到它。当我从 iFrame 中单击按钮以解锁成就时,它不会解锁。记录 $result 将返回 1,但它不会显示在代码中或算作未锁定。
成就后.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;
}
成就.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);
}
}
}
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);
}