๐Ÿš€ 8.9 Released! โ†’ โšก๏ธ New Node-API Engine Preview, ๐Ÿ“ฒ ns widget ios, ๐Ÿ’… Tailwind v4 and more...
Read Announcement

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