Preview 2.0 is now in Public Beta!
Read the Announcement

@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

NameTypeDescription
appIDstring
dataAccessExpirationDateDatereadonly
dataAccessExpiredbooleanreadonly
declinedPermissionsstring[]readonly
expirationDateDatereadonly
expiredbooleanreadonly
expiredPermissionsstring[]readonly
graphDomainstringreadonly
permissionsstring[]readonly
refreshDateDatereadonly
tokenStringstringreadonly
userIDstringreadonly
currentAccessToken()AccessTokenA static method that returns an access token.
currentAccessTokenIsActivebooleanreadonly
iosFBSDKAccessTokenreadonly. iOS access token.
androidAccessTokenreadonly. Android access token.

LoginResult Class

NameTypeDescription
androidLoginManagerreadonly. Native instance for Android.
iosFBSDKLoginManagerreadonly. Native instance for iOS.
grantedPermissionsstring[]readonly
isCancelledbooleanreadonly
tokenAccessTokenreadonly

LoginManager Class

NameType/Return TypeDescription
static init()voidInitializes 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()voidLogs out the user.

License

Apache License Version 2.0