这是您可以直接在 AS3 中完成所有操作的另一种方式(非常方便)
这是我在 facebook 上构建的游戏的代码片段,它需要在游戏中的某个时间点获得权限.. 它运行良好。(请注意,您现在必须在 init 调用中指定 channel.html 和 oauth: true )
首先确保您拥有最新版本的 API(现在为 1.7)(http://code.google.com/p/facebook-actionscript-api)
private function facebookInit():void // START THE SESSION…
{
Facebook.init(APP_ID, facebookInitHandler,{
appId: APP_ID,
status: true,
cookie: true,
xfmbl: true,
channelUrl: ‘http://yoursiteurl/channel.html',
oauth: true,
perms: “publish_stream,email”
});
}
private function facebookInitHandler(response:Object, fail:Object):void
{
if (response.accessToken)
{
userAccessToken = JSON.encode(response.accessToken);
facebookLoggedInWithToken = true;
loadProfileData();
} else {
facebookLoggedInWithToken = false;
}
}
private function loadProfileData():void
{
var request:String = ‘/me’;
var requestType:String = ‘GET’;
var params:Object = null;
Facebook.api(request, loadProfileDataHandler, params, requestType);
}
private function loadProfileDataHandler(response:Object, fail:Object):void
{
if (response) {
userID = response.id;
fullName = response.name;
firstName = response.first_name;
lastName = response.last_name;
userEmail = response.email;
userPicURL = ‘http://graph.facebook.com/‘ + userID + ‘/picture’;
}
}
请享用!