Plugins
@nativescript/facebook
Contents
Intro
A plugin that allows you to integrate Facebook Login with your app using the Facebook SDK.
Installation
Install the plugin to add the Facebook SDK by running the following command:
npm install @nativescript/facebook
Android prerequisites
Set up your app to use the Facebook SDK for Android by following the instructions under the following sections in Getting Started Guide.
iOS prerequisites
Set up your app to use the Facebook SDK for iOS by following the instructions in the following sections on Getting Started Guide:
Use @nativescript/facebook
Sign in the user
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) {}
Sign out the user
To log the user out, call the logOut
method.
LoginManager.logOut()
API
LoginManager class
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. |
LoginResult class
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 |
AccessToken class
This class provides the data of a Facebook access token.
Properties
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. |
Methods
| Method | Returns | | :--------------------- | :-------------------------------- | ------------------------------------------------------------------------------------- | | currentAccessToken()
| AccessToken | A static method that returns an access token as an instance of the AccessToken class. |
To log the user out, call the logOut
method.
LoginManager.logOut()
API
AccessToken
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. |
LoginResult Class
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 |
LoginManager Class
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. |
License
Apache License Version 2.0
- Previous
- Next
- Fingerprint-Auth