ActionScript 3 AS3:Facebook身份验证示例
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 AS3:Facebook身份验证示例相关的知识,希望对你有一定的参考价值。
import com.facebook.commands.friends.GetFriends;
import com.facebook.data.users.FacebookUser;
import com.facebook.data.friends.GetFriendsData;
import com.facebook.events.FacebookEvent;
import com.facebook.Facebook;
import com.facebook.net.FacebookCall;
import com.facebook.utils.FacebookSessionUtil;
import flash.display.Stage;
import flash.display.LoaderInfo;
import mx.controls.Alert;
private var API_KEY:String = "API_KEY";
private var SECRET_KEY:String = "SECRET_KEY";
private var fbook:Facebook;
private var fbLoaderInfo:LoaderInfo;
private var fbSession:FacebookSessionUtil;
private var currentMethod:Function;
private function initApp():void
{
fbLoaderInfo = stage.loaderInfo;
getFriends();
}
/**************************************
* Actions
**************************************/
private function getFriends():void
{
//If the user is not logged in, force one
if( !isAuthenticated() ){ fbLogin( arguments.callee ); return }
var call:FacebookCall = fbook.post( new GetFriends( ) );
call.addEventListener( FacebookEvent.COMPLETE, getFriendsCompleteHandler, false, 0, true );
}
private function getFriendsCompleteHandler( e:FacebookEvent ):void
{
if( e.error ) trace( "getFriendsCompleteHandler: " + e.error);
var friendsData:GetFriendsData = e.data as GetFriendsData;
//Iterate through the albumsResponseData.albumCollection to get the titles
for( var i:uint = 0; i < friendsData.friends.length; i++ ){
var friendID:Number = friendsData.friends.getItemAt(i).uid;
var facebookUser:FacebookUser = friendsData.friends.getUserById( friendID );
trace( "Facebook User Name: " + facebookUser.name );
}
}
/**************************************
* Facebook Authentication
**************************************/
private function fbLogin( method:Function ):void
{
currentMethod = method;
fbSession = new FacebookSessionUtil( API_KEY, SECRET_KEY, loaderInfo );
fbSession.addEventListener( FacebookEvent.WAITING_FOR_LOGIN, fbWaitingForLoginHandler, false, 0, true );
fbSession.addEventListener( FacebookEvent.CONNECT, fbOnConnectHandler, false, 0, true );
fbook = fbSession.facebook;
fbSession.login();
}
private function isAuthenticated():Boolean
{
if( fbSession == null || !fbook.is_connected ) return false;
return true;
}
/**************************************
* Facebook Event Handlers
**************************************/
private function fbOnConnectHandler( e:FacebookEvent ):void
{
trace( "You are logged into Facebook" );
//Continue where the user last left off before requiring Authentication
currentMethod();
}
private function fbWaitingForLoginHandler( e:FacebookEvent ):void
{
//The user has returned from the log-in page and are now clicking "OK"
var alert:Alert = Alert.show( "Click 'OK' after you've logged in", "Logging In" );
alert.addEventListener( Event.CLOSE, alertCloseHandler, false, 0, true );
alert.addEventListener( Event.CLOSE, fbValidateLogin, false, 0, true );
}
private function fbValidateLogin( e:Event ):void
{
fbSession.validateLogin();
}
private function alertCloseHandler( e:Event ):void
{
}
以上是关于ActionScript 3 AS3:Facebook身份验证示例的主要内容,如果未能解决你的问题,请参考以下文章
[ActionScript 3.0] AS3.0 水面波纹效果