npm i --save @nativescript/facebook
- Version: 2.2.0
- GitHub: https://github.com/NativeScript/plugins
- NPM: https://www.npmjs.com/package/%40nativescript%2Ffacebook
- Downloads:
- Last Day: 11
- Last Week: 75
- Last Month: 299
@nativescript/facebook
Installation
npm install @nativescript/facebook
Prerequisites
Android
Before you can run the project, follow the Getting Started Guide for Facebook Android SDK to set up a Facebook app. You can skip the build.gradle changes since that's taken care of by the rnpm link step above, but make sure you follow the rest of the steps such as updating strings.xml
and AndroidManifest.xml
.
iOS
Follow step 3 in the Getting Started Guide for Facebook SDK for iOS.
Usage
First of all, you should initialize the LoginManager by calling the init
method.
import { LoginManager } from '@nativescript/facebook';
LoginManager.init()
Then to log the user in, use the logInWithPermissions
method.
You can also use the Login Manager with custom UI to perform Login.
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()
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