Package | com.myflashlab.air.extensions.facebook |
Class | public class FB |
Inheritance | FB ![]() |
FB.getInstance("0000000");
where you pass in your Facebook app you have already created in your facebook developer panel.
Make sure to take care of the permissions manually if you are targeting AIR SDK 24+: https://github.com/myflashlab/facebook-ANE/#permissions
Property | Defined By | ||
---|---|---|---|
auth : Auth [static]
gives you access to login/logout options and also you can get your current active token and all the information
you may need about permissions that your users may have or may have not accepted while using your app. | FB | ||
graph : Graph [static]
gives you access to the facebook official OpenGraph API. | FB | ||
hashKey : String [static] [read-only]
(Android only) When developing your application, your facebook developer consoles will ask you to enter your app hash key so your app will safely be
connected to your facebook app. | FB | ||
logManager : Auth [static]
depricated, please use FB.auth instead. | FB | ||
os : String [static] [read-only]
indicates the current OS which the app is running in. | FB |
Method | Defined By | ||
---|---|---|---|
FB($appId:String)
do NOT initialize with the constructor. | FB | ||
appInvite($linkUrl:String, $imgUrl:String, $callback:Function):Boolean [static]
Use this method to let your users invite their friends to engage with your app. | FB | ||
clearUserId():void [static]
You can delete the ID stored on the device by calling the clearUserId() function. | FB | ||
createLikeBtn($url:String, $style:int, $type:int, $stage:Stage = null):LikeBtn [static]
Use this method to create a new instance of facebook Like button. | FB | ||
dispose():void [static]
Call this method to dispose the extension. | FB | ||
getInstance($appId:String):FB [static]
This is the main method to be called with this extension. | FB | ||
logEvent($eventName:String, $valueToSum:Number = -1, $parameters:Object = null):void [static]
Log an app event with the specified name, supplied value, and set of parameters. | FB | ||
removeLikeBtns():void [static]
although you can dispose and remove like buttons individually, this method will help you remove them all at once. | FB | ||
setUserId($userID:String):void [static]
By calling the setUserID function, you can assign an ID that's meaningful to you to a user of your app,
for example a number that associates the user with information you collected when they installed your app. | FB | ||
share($model:SharinModel, $callback:Function):Boolean [static]
Create a model of what content you want to share and then pass the model to this method to take care of the rest. | FB | ||
updateUserProperties($properties:Object, $callback:Function):void [static]
An AS3 Object of key-value pairs representing user properties and their values. | FB |
Constant | Defined By | ||
---|---|---|---|
ANDROID : String = android [static] | FB | ||
EXTENSION_ID : String = com.myflashlab.air.extensions.facebook [static]
Extension ID for this extension
| FB | ||
IOS : String = ios [static] | FB | ||
VERSION : String = 4.22.5 [static]
current version number of this extension
| FB |
auth | property |
public static var auth:Auth
gives you access to login/logout options and also you can get your current active token and all the information you may need about permissions that your users may have or may have not accepted while using your app.
do not try to initialize this class explicitly you must access auth
only by calling through FB.auth
graph | property |
public static var graph:Graph
gives you access to the facebook official OpenGraph API. you can request information from the graph using the request
method in this class.
IMPORTANT: based on your permissions uppon logging in, you may do many different things using the graph. Things like sharing posts or find out about your user interests, their friends and many more. if you want to use the graph like a pro, you really need to read the facebook docs here: https://developers.facebook.com/docs/graph-api/reference
do not try to initialize this class explicitly you must access the graph only by calling through FB.graph
hashKey | property |
hashKey:String
[read-only]
(Android only) When developing your application, your facebook developer consoles will ask you to enter your app hash key so your app will safely be
connected to your facebook app. to do so, all you have to do is to first initialize the extension by calling getInstance("000000");
and then call this property and the hash key will be generated and returned to you. use this hash code in your facebook console and of course
you won't be needing to call this prop ever again.
public static function get hashKey():String
Error — error before calling any of the static methods of this calss, you need to have called getInstance("000000"); in your project.
|
logManager | property |
public static var logManager:Auth
depricated, please use FB.auth
instead.
os | property |
os:String
[read-only] indicates the current OS which the app is running in. it's either FB.ANDROID or FB.IOS
public static function get os():String
FB | () | Constructor |
public function FB($appId:String)
do NOT initialize with the constructor.
instead use getInstance("000000");
and pass in your facebook application ID.
$appId:String |
See also
appInvite | () | method |
public static function appInvite($linkUrl:String, $imgUrl:String, $callback:Function):Boolean
Use this method to let your users invite their friends to engage with your app. if they have your app already installed, they will see a "play" button and if they don't have it installed, they will see an "install" button which will open Google Store or app store depending on their mobile device.
for more information about app invitations, read here: https://developers.facebook.com/docs/app-invites/overview
Parameters
$linkUrl:String — your app's unique app link. you can generate it here https://developers.facebook.com/docs/applinks -
https://developers.facebook.com/quickstarts/?platform=app-links-host
| |
$imgUrl:String — any image URL which you like your users see when they are inviting their friends.
| |
$callback:Function — a function which will be called to report your invitation state.
|
Boolean — |
clearUserId | () | method |
public static function clearUserId():void
You can delete the ID stored on the device by calling the clearUserId() function. After you delete the ID, app events from the device are sent without a user ID.
createLikeBtn | () | method |
public static function createLikeBtn($url:String, $style:int, $type:int, $stage:Stage = null):LikeBtn
Use this method to create a new instance of facebook Like button. you will not be able to change the design of this button of course. it's hardcoded inside the SDK. what you can do is to tell the button what to URL to like!
it's important to mention that creating a new like button is not very CPU friendly and may freez your UI for a few milli seconds. as a workaround, try updating your buttons instead of recreating them. link and style of like buttons can be updated at runtime with no problem.
When you create a new like button, you can register a listener to know when it is added to the stage and then you can know the real width/height of the button which will help you put it inside your app design. to move the button around, you can easily use the x,y properties.
NOTICE: like button will work even if your users are not logged in to your app.
Parameters
$url:String — the url you wish to be liked
| |
$style:int — the style of how the like button would look
| |
$type:int — the url type. it can be a facebook page, or a normal web page link.
| |
$stage:Stage (default = null ) — your flash stage. This is required to correct dimentions of the like button in iOS
|
LikeBtn — |
Error — error before calling any of the static methods of this calss, you need to have called getInstance("000000"); in your project.
|
See also
var like:LikeBtn = FB.createLikeBtn("https://www.facebook.com/myflashlab", LikeBtn.STYLE_STANDARD, LikeBtn.LINK_TYPE_PAGE); like.name = "myBtnName"; // you may need this name later to address to your button. // add listeners to your button to know about its state like.addEventListener(FBEvent.LIKE_BTN_CREATED, onBtnCreated); like.addEventListener(FBEvent.LIKE_BTN_ERROR, onBtnError); like.addEventListener(FBEvent.LIKE_BTN_UPDATED, onBtnUpdated); function onBtnCreated(e:FBEvent):void { var btn:LikeBtn = e.target as LikeBtn; // get the real dimension of this button trace("width = " + btn.width); trace("height = " + btn.height); // feel free to update your link whenever you wish. it is much faster than creating a new button. btn.update("http://www.myappsnippet.com/", LikeBtn.STYLE_BOX_COUNT, LikeBtn.LINK_TYPE_OPEN_GRAPH); // change the position of your button anytime you wish at runtime btn.x = Math.random() 600; btn.y = Math.random() 600; } function onBtnError(e:FBEvent):void { var btn:LikeBtn = e.target as LikeBtn; trace("e.param = " + e.param); } function onBtnUpdated(e:FBEvent):void { var btn:LikeBtn = e.target as LikeBtn; // maybe you like to remove your button? do it like below // btn.removeEventListener(FBEvent.LIKE_BTN_CREATED, onBtnCreated); // btn.removeEventListener(FBEvent.LIKE_BTN_ERROR, onBtnError); // btn.removeEventListener(FBEvent.LIKE_BTN_UPDATED, onBtnUpdated); // btn.dispose(); // btn = null; }
dispose | () | method |
public static function dispose():void
Call this method to dispose the extension. you will need to initialize it fresh like FB.getInstance("000000");
if you want to use it again.
Error — error before calling any of the static methods of this calss, you need to have called getInstance("000000"); in your project.
|
getInstance | () | method |
public static function getInstance($appId:String):FB
This is the main method to be called with this extension. you need to create a new facebook app in your facebook developer account first and then enter your app ID here. when you do this, the doors will open for you to enjoy facebook SDK integrated in your project! :)
Parameters
$appId:String |
FB — returns an instance of the Facebook extension. you really won't be needing it. I just put it for your convenient.
|
logEvent | () | method |
public static function logEvent($eventName:String, $valueToSum:Number = -1, $parameters:Object = null):void
Log an app event with the specified name, supplied value, and set of parameters. $valueToSum
and $parameters
are optional.
Parameters
$eventName:String — $eventName used to denote the event. Choose amongst the EVENT_NAME_ constants in AppEventsConstants when possible. Or create your own
if none of the EVENT_NAME_constants are applicable. Event names should be
40 characters or less, alphanumeric, and can include spaces, underscores or
hyphens, but must not have a space or hyphen as the first character. Any
given app should have no more than 1000 distinct event names.
| |
$valueToSum:Number (default = -1 ) — a value to associate with the event which will be summed up in Insights for
across all instances of the event, so that average values can be
determined, etc.
| |
$parameters:Object (default = null ) — A Bundle of parameters to log with the event. Insights will allow looking
at the logs of these events via different parameter values. You can log on
the order of 25 parameters with each distinct eventName. It's advisable to
limit the number of unique values provided for each parameter in the
thousands. As an example, don't attempt to provide a unique
parameter value for each unique user in your app. You won't get meaningful
aggregate reporting on so many parameter values. The values in the bundles
should be Strings.
|
removeLikeBtns | () | method |
public static function removeLikeBtns():void
although you can dispose and remove like buttons individually, this method will help you remove them all at once.
Error — error before calling any of the static methods of this calss, you need to have called getInstance("000000"); in your project.
|
setUserId | () | method |
public static function setUserId($userID:String):void
By calling the setUserID function, you can assign an ID that's meaningful to you to a user of your app, for example a number that associates the user with information you collected when they installed your app. Typically this is your identifier for the user in your own backend systems. This is a good feature to use if you expect to upload data from your app and use the API - as this ensures we're attributing properties to the same user.
Parameters
$userID:String — The user ID. The length of the user ID must be less than 100 characters.
|
share | () | method |
public static function share($model:SharinModel, $callback:Function):Boolean
Create a model of what content you want to share and then pass the model to this method to take care of the rest.
NOTICE: Sharing works no matter if your user has already loggedin to your app or not. but you must know that if your user is not loggedin, you will not be able to know if the user has successfully shared your content or they have dissmissed the sharing dialog! I know, this really sucks but that's how Facebook SDK works!
Parameters
$model:SharinModel — The model of sharing. it can be a link, a photo or a video (V1.0 supports link sharing only)
| |
$callback:Function — The sharing result will be dispatched through this callback.
|
Boolean — returns true if the method has been called successfully. this does NOT mean that the sharing has been completed. to know if the
sharing has been completed, you must use register a callback function.
|
Error — error before calling any of the static methods of this calss, you need to have called getInstance("000000"); in your project.
|
var shareModel:ShareLink = new ShareLink(); shareModel.contentTitle = "title!"; shareModel.contentURL = "http://myappsnippet.com"; shareModel.imageURL = "http://myappsnippet.com/wp-content/uploads/2015/07/bundle-Jul-2015-adobe-air-extension_preview.jpg"; shareModel.contentDescription = "description!"; FB.share(shareModel, onSharingResult); function onSharingResult($status:String, $msg:String):void { // $status will be one of the following: // FBEvent.SHARING_DONE // FBEvent.SHARING_CANCELED // FBEvent.SHARING_ERROR // if it is "FBEvent.SHARING_ERROR", then $msg will explain the error reason trace($status); }
updateUserProperties | () | method |
public static function updateUserProperties($properties:Object, $callback:Function):void
An AS3 Object of key-value pairs representing user properties and their values. Values should be strings or numbers only. Each key must be less than 40 character in length, and the key can contain only letters, number, whitespace, hyphens (-), or underscores (_). Each value must be less than 100 characters. The total number of properties associated with your users cannot exceed 100.
Parameters
$properties:Object | |
$callback:Function |
ANDROID | Constant |
public static const ANDROID:String = android
EXTENSION_ID | Constant |
public static const EXTENSION_ID:String = com.myflashlab.air.extensions.facebook
Extension ID for this extension
IOS | Constant |
public static const IOS:String = ios
VERSION | Constant |
public static const VERSION:String = 4.22.5
current version number of this extension