Package | com.myflashlab.air.extensions.facebook.access |
Class | public class Auth |
Inheritance | Auth ![]() |
Loging your users to your app is the most important task you may need when working with a facebook extension in your app. This class will provide you everything you would need about logging in and out with letting you know about the permissions that the user has given to you and also this class will provide you with the token id of the current active session in your app. (you may use the token for complex graph API calls.)
What I like to emphasize here is that you should forget the word "login" when working with facebook SDK! because you are actually requesting for permissions from your users. if they grand you with the permissions you are asking, then they can use your app features.
The beauty of this system is that you can easily manage what features your users can have access to based on the permissions they have granded.
The best practice is to ask for more permissions in your app ONLY when you need them. do NOT scare your users too quickly! :)
See also
Property | Defined By | ||
---|---|---|---|
declinedPermissions : Array [read-only]
returns an array of permissions which your user did NOT allow. | Auth | ||
isLogin : Boolean [read-only]
indicates if you are already logged in or not. | Auth | ||
permissions : Array [read-only]
returns an array of permissions which your user has granted to your app. | Auth | ||
token : String [read-only]
if you are logged in, this will return the token you may find useful in complex graph calls. | Auth |
Method | Defined By | ||
---|---|---|---|
logout():void
Call this method to logout. | Auth | ||
requestPermission($withPublishPermissions:Boolean, ... rest):Boolean
use this method to login your users to your app based on the list of permissions you need. | Auth |
Constant | Defined By | ||
---|---|---|---|
WITH_PUBLISH_PERMISSIONS : Boolean = true [static]
Does not work on Android yet!
| Auth | ||
WITH_READ_PERMISSIONS : Boolean = false [static]
read permissions grant you access to different information availble on users facebook account. | Auth |
declinedPermissions | property |
declinedPermissions:Array
[read-only] returns an array of permissions which your user did NOT allow.
public function get declinedPermissions():Array
isLogin | property |
isLogin:Boolean
[read-only] indicates if you are already logged in or not.
public function get isLogin():Boolean
permissions | property |
permissions:Array
[read-only] returns an array of permissions which your user has granted to your app.
public function get permissions():Array
token | property |
token:String
[read-only]
if you are logged in, this will return the token you may find useful in complex graph calls.
IMPORTANT: token expires very often. so when you call the graph, it may return error messages and you should parse the returned
json and renew your token if required. renewing the token is easy! simply call the requestPermission
method again.
public function get token():String
logout | () | method |
public function logout():void
Call this method to logout. as soon as you call this method, the token value will be nulled.
requestPermission | () | method |
public function requestPermission($withPublishPermissions:Boolean, ... rest):Boolean
use this method to login your users to your app based on the list of permissions you need.
Parameters
$withPublishPermissions:Boolean | |
... rest — rest
|
Boolean — returns true if the method has been called successfully. this does NOT mean that the login process has been completed. to know if the
login has been completed, you must use add listeners.
|
WITH_PUBLISH_PERMISSIONS | Constant |
public static const WITH_PUBLISH_PERMISSIONS:Boolean = true
Does not work on Android yet!
WITH_READ_PERMISSIONS | Constant |
public static const WITH_READ_PERMISSIONS:Boolean = false
read permissions grant you access to different information availble on users facebook account.
NOTICE: sharing, is completly independent from the login procedure. you will be able to share content without any logging in required at all
FB.auth.addEventListener(FBEvent.LOGIN_DONE, onLoginSuccess); FB.auth.addEventListener(FBEvent.LOGIN_CANCELED, onLoginCanceled); FB.auth.addEventListener(FBEvent.LOGIN_ERROR, onLoginError); // an array of permissions. you can add or remove items from this array anytime you like FB.auth.requestPermission(Auth.WITH_READ_PERMISSIONS, Permissions.public_profile, Permissions.user_friends, Permissions.email); function onLoginSuccess(event:FBEvent):void { FB.auth.removeEventListener(FBEvent.LOGIN_DONE, onLoginSuccess); FB.auth.removeEventListener(FBEvent.LOGIN_CANCELED, onLoginCanceled); FB.auth.removeEventListener(FBEvent.LOGIN_ERROR, onLoginError); trace("onLoginSuccess"); trace("token = " + FB.auth.token); trace("permissions = " + FB.auth.permissions); trace("declined Permissions = " + FB.auth.declinedPermissions); } function onLoginCanceled(event:FBEvent):void { FB.auth.removeEventListener(FBEvent.LOGIN_DONE, onLoginSuccess); FB.auth.removeEventListener(FBEvent.LOGIN_CANCELED, onLoginCanceled); FB.auth.removeEventListener(FBEvent.LOGIN_ERROR, onLoginError); trace("onLoginCanceled"); } function onLoginError(event:FBEvent):void { FB.auth.removeEventListener(FBEvent.LOGIN_DONE, onLoginSuccess); FB.auth.removeEventListener(FBEvent.LOGIN_CANCELED, onLoginCanceled); FB.auth.removeEventListener(FBEvent.LOGIN_ERROR, onLoginError); trace("onLoginError = " + event.param); }