Facebook Plugin for Cordova 5.0+
- Cordova >= 5.0.0
- iOS and Android
- Login, Graph Requests, App Events
Get the Plugin:
$> cordova plugin add cordova-plugin-facebook --variable FACEBOOK_DISPLAY_NAME=<Your App Name> --variable FACEBOOK_APP_ID=<Your App ID> [--save]
Using the Plugin:
CordovaFacebook defines a single variable on
CordovaFacebook methods accept exactly one argument:
options, of type
Passing in a function as
options.onFailure will allow you to listen to the result of that method.
onFailure callbacks will generally be passed one argument (whose type may vary) as the result.
CordovaFacebook.login method accepts a
permissions field in addition to the standard callbacks.
permissions(optional) - an array of Facebook permissions you are asking for from the user.
"public_profile"is always requested. See Facebook's Docs for more information.
onFailure receive a single
result object, with the following properties:
1if there was an error,
1if the user accepted the login request,
1if the user cancelled the login request,
erroris 1) - Facebook's error code for what went wrong.
0is a network failure,
304is a login mismatch (call
logoutbefore trying again). See Facebook List of Error Codes.
erroris 1) - Facebook's localized description of what went wrong, in the current locale.
successis 1) - An array of the permissions the user approved.
successis 1) - An array of the permissions the user declined.
result.accessToken(if available) - The Facebook Access Token for the User.
result.userID(if available) - The Facebook User ID for the User.
CordovaFacebook.logout method does not have any additional options other than the standard callbacks.
logout method will always succeed, and never fail. (Meaning
onFailure will never be called).
onSuccess callback is not passed any arguments.
CordovaFacebook;// Unless you need to wait for the native sdk to do its thing,// you dont even really need to use a callback:CordovaFacebook;