A plugin that allows you to integrate Facebook Login with your app using the Facebook SDK.
Install the plugin to add the Facebook SDK by running the following command:
npm install @nativescript/facebook
Set up your app to use the Facebook SDK for Android by following the instructions under the following sections in Getting Started Guide.
Set up your app to use the Facebook SDK for iOS by following the instructions in the following sections on Getting Started Guide:
Firstly, initialize the LoginManager by calling the init
method.
import { LoginManager } from '@nativescript/facebook';
LoginManager.init()
Next, to sign the user in, call the logInWithPermissions
method.
import { LoginManager, AccessToken } from '@nativescript/facebook';
try {
const result = await LoginManager.logInWithPermissions(['public_profile']); // LoginResult
const accessToken = AccessToken.currentAccessToken();
} catch (e) {}
To log the user out, call the logOut
method.
LoginManager.logOut()
The LoginManager class provides the following static methods:
Method | Returns | Description |
---|---|---|
static init() |
void |
Initializes the LoginManager. Call this method early in the app lifecycle and the best place for that is the main.ts file. |
static logInWithPermissions(permissions: string[], context?: any) |
Promise<LoginResult> | Opens the login window in the optionally provided context (a UIViewController instance on iOS and an Activity The permissions parameter indicates the data about the user the app would like to get from Facebook. |
static logout() |
void |
Logs out the user. |
This class provides the login data returned by the logInWithPermissions
method.
Name | Type | Description |
---|---|---|
android |
LoginManager | readonly. Native instance for Android. |
ios |
FBSDKLoginManager | readonly. Native instance for iOS. |
grantedPermissions |
string[] |
readonly |
isCancelled |
boolean |
readonly |
token |
AccessToken | readonly |
This class provides the data of a Facebook access token.
Property | Type | Description |
---|---|---|
appID |
string |
|
dataAccessExpirationDate |
Date |
readonly |
dataAccessExpired |
boolean |
readonly |
declinedPermissions |
string[] |
readonly |
expirationDate |
Date |
readonly |
expired |
boolean |
readonly |
expiredPermissions |
string[] |
readonly |
graphDomain |
string |
readonly |
permissions |
string[] |
readonly |
refreshDate |
Date |
readonly |
tokenString |
string |
readonly |
userID |
string |
readonly |
currentAccessTokenIsActive |
boolean |
readonly |
ios |
FBSDKAccessToken | readonly. iOS access token. |
android |
AccessToken | readonly. Android access token. |
Method | Returns |
---|---|
currentAccessToken() |
AccessToken |
To log the user out, call the logOut
method.
LoginManager.logOut()
Name | Type | Description |
---|---|---|
appID |
string |
|
dataAccessExpirationDate |
Date |
readonly |
dataAccessExpired |
boolean |
readonly |
declinedPermissions |
string[] |
readonly |
expirationDate |
Date |
readonly |
expired |
boolean |
readonly |
expiredPermissions |
string[] |
readonly |
graphDomain |
string |
readonly |
permissions |
string[] |
readonly |
refreshDate |
Date |
readonly |
tokenString |
string |
readonly |
userID |
string |
readonly |
currentAccessToken() |
AccessToken |
A static method that returns an access token. |
currentAccessTokenIsActive |
boolean |
readonly |
ios |
FBSDKAccessToken | readonly. iOS access token. |
android |
AccessToken | readonly. Android access token. |
Name | Type | Description |
---|---|---|
android |
LoginManager | readonly. Native instance for Android. |
ios |
FBSDKLoginManager | readonly. Native instance for iOS. |
grantedPermissions |
string[] |
readonly |
isCancelled |
boolean |
readonly |
token |
AccessToken | readonly |
Name | Type/Return Type | Description |
---|---|---|
static init() |
void |
Initializes the LoginManager. You should call this method early in the app lifecycle and the best place for that is the main.ts . |
static logInWithPermissions(permissions: string[], context?: any) |
Promise<LoginResult> |
Opens the login window in the optionally provided context (a UIViewController instance on iOS and an [Activity](https://developer.android.The permissions parameter indicates the data about the user the app would like to get from Facebook. |
static logout() |
void |
Logs out the user. |
Apache License Version 2.0