Authorizing a Facebook account

The user session information is passed to Flash via flashvars parameters.

if (loaderInfo.parameters.fb_sig_added == undefined) {
// do nothing when the flash is compiled from Flash IDE
}
else if(loaderInfo.parameters.fb_sig_added == true){
var session:FacebookSessionUtil=new FacebookSessionUtil(loaderInfo.parameters.fb_sig_api_key,null,loaderInfo);
_fb=session.Facebook;
session.addEventListener(FacebookEvent.CONNECT,onConnect);
session.verifySession();
}else{
navigateToURL(new URLRequest("http://www.Facebook.com/login.php?api_key="+loaderInfo.parameters.fb_sig_api_key),"_top");
}

In our first example, we try to simply put the Flash virtual world inside the Facebook platform. Therefore, we leave the onConnect function as a placeholder.

private function onConnect(e:FacebookEvent):void {
if(e.success){
trace("Connected Facebook");
}
else{
trace("Failed to connect to Facebook");
}
}

Getting the profile name and picture from Facebook

We are going to fetch the basic profile information and display it as login name and the profile information panel.

Getting the profile name and picture from Facebook

After the connection between Flash and Facebook is established, we fetch the square profile picture and the name from Facebook.

private function onConnect(e:FacebookEvent):void {
if(e.success){
var fbcall:FacebookCall=_fb.post(new GetInfo([_fb.uid],[GetInfoFieldValues.PIC_SQUARE,GetInfoFieldValues.NAME]));
fbcall.addEventListener(FacebookEvent.COMPLETE, onGetInfo);
}
}

The Adobe Facebook API will trace every Facebook request for debug use. We can take a look at the Restful URL request of the users.getInfo command.

http://api.Facebook.com/restserver.php
?uids=100001017913437
&api_key=3fe38aa87a48b6416458afa3daee40d5
&method=users.getInfo
&sig=46b367dd97079edf462d5790e661cad7
&session_key=2.tH8YdlQiDZvPn4Dd0o7Zjg__.3600.1271516400-100001017913437
&fields=pic_square,name
&ss=true&v=1.0
&call_id=12715119668660

While posting an unfamiliar Facebook call, we should take a look at the Facebook Developer Wiki. For example, we can get the whole document of the parameters and result of the users.getInfo command on http://wiki.developers.Facebook.com/index.php/Users.getInfo. It contains detailed description on the command and the input/output of the API function to let us know how to use it.

The parameters in the URL match the document of the command from the Facebook Developer Wiki. The fields contain what we want to get from Facebook. They are pic_square and name.

Facebook returns the result in XML format:

<?xml version="1.0" encoding="UTF-8"?>
<users_getInfo_response xmlns="http://api.Facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://api.Facebook.com/1.0/ http://api.Facebook.com/1.0/Facebook.xsd" list="true">
<user>
<name>Steven Mak</name>
<uid>100001017913437</uid>
<pic_square>http://profile.ak.fbcdn.net/hprofile-ak-sf2p/hs273.snc3/23222_100001017913437_530_q.jpg</pic_square>
</user>
</users_getInfo_response>

The Facebook client API will parse the returning XML result and pack it into an ActionScript object for us to use. We fill the returning name in the username text field of the login box. We will store the profile picture for later use.

private function onGetInfo(e:FacebookEvent):void {
// remove the event listener after completed the request.
e.target.removeEventListener(FacebookEvent.COMPLETE, onGetInfo);
if(e.success){
var user:FacebookUser = (e.data as GetInfoData).userCollection.getItemAt(0) as FacebookUser;
loginBox.nameInput.text = user.name;
Myself.instance.profilePic = user.pic_square;
}
}

Note

As we will have different event handlers to listen to the FacebookEvent.COMPLETE event for different purposes, we need to remove the event listener after completing the Facebook request.

The URL of the profile picture is stored in user variables so that every client in the same room can get the profile picture of the user and display it.

params.profilePic = Myself.instance.profilePic;

In the player's information panel, we will use Loader to load the profile picture and display it in the panel.

var profilePic:String = targetUser.getVariable('profilePic'),
if (profilePic != undefined || profilePic != '') {
_loader = new Loader();
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, profilePicLoaded);
_loader.load(new URLRequest(profilePic));
}
private function profilePicLoaded(e:Event):void {
this.profile_pic.addChild(_loader);
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.160.156