8.8 released—CSS Media Query support, SF Symbols and much more...
Learn more

View on GitHub

@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:

cli
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.

ts
import { LoginManager } from '@nativescript/facebook'

LoginManager.init()

Next, to sign the user in, call the logInWithPermissions method.

ts
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.

ts
LoginManager.logOut()

API

LoginManager class

The LoginManager class provides the following static methods:

MethodReturnsDescription
static init()voidInitializes 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()voidLogs out the user.

LoginResult class

This class provides the login data returned by the logInWithPermissions method.

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

AccessToken class

This class provides the data of a Facebook access token.

Properties

PropertyTypeDescription
appIDstring
dataAccessExpirationDateDatereadonly
dataAccessExpiredbooleanreadonly
declinedPermissionsstring[]readonly
expirationDateDatereadonly
expiredbooleanreadonly
expiredPermissionsstring[]readonly
graphDomainstringreadonly
permissionsstring[]readonly
refreshDateDatereadonly
tokenStringstringreadonly
userIDstringreadonly
currentAccessTokenIsActivebooleanreadonly
iosFBSDKAccessTokenreadonly. iOS access token.
androidAccessTokenreadonly. 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.

ts
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

Previous
Email