|
1 | 1 | # @nativescript/facebook
|
2 | 2 |
|
| 3 | +## Contents |
| 4 | +* [Intro](#intro) |
| 5 | +* [Installation](#installation) |
| 6 | +* [Android prerequisites](#android-prerequisites) |
| 7 | +* [iOS prerequisites](#ios-prerequisites) |
| 8 | +* [Use @nativescript/facebook](#use-nativescriptfacebook) |
| 9 | + * [Sign in the user](#sign-in-the-user) |
| 10 | + * [Sign out the user](#sign-out-the-user) |
| 11 | +* [API](#api) |
| 12 | + * [LoginManager class](#loginmanager-class) |
| 13 | + * [LoginResult class](#loginresult-class) |
| 14 | + * [AccessToken class](#accesstoken-class) |
| 15 | + * [Properties](#properties) |
| 16 | + * [Methods](#methods) |
| 17 | + |
| 18 | +## Intro |
| 19 | + |
| 20 | +A plugin that allows you to integrate Facebook Login with your app using the Facebook SDK. |
| 21 | + |
3 | 22 | ## Installation
|
| 23 | + |
| 24 | +Install the plugin to add the Facebook SDK by running the following command: |
| 25 | + |
4 | 26 | ```cli
|
5 | 27 | npm install @nativescript/facebook
|
6 | 28 | ```
|
7 | 29 |
|
8 |
| -## Prerequisites |
| 30 | +## Android prerequisites |
| 31 | + |
| 32 | +Set up your app to use the Facebook SDK for Android by following the instructions under the following sections in [Getting Started Guide](https://developers.facebook.com/docs/android/getting-started/). |
9 | 33 |
|
10 |
| -### Android |
| 34 | +- [Get Your App ID](https://developers.facebook.com/docs/android/getting-started#app-id) |
| 35 | +- [Get Your Client Token](https://developers.facebook.com/docs/android/getting-started#client-token) |
| 36 | +- [Update Your Manifest](https://developers.facebook.com/docs/android/getting-started/#add-app_id) |
11 | 37 |
|
12 |
| -Before you can run the project, follow the [Getting Started Guide](https://developers.facebook.com/docs/android/getting-started/) 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`. |
| 38 | +## iOS prerequisites |
13 | 39 |
|
14 |
| -### iOS |
| 40 | +Set up your app to use the Facebook SDK for iOS by following the instructions in the following sections on [Getting Started Guide](https://developers.facebook.com/docs/ios/getting-started#getting-started-with-the-facebook-sdk-for-ios): |
15 | 41 |
|
16 |
| -Follow step 3 in the [Getting Started Guide](https://developers.facebook.com/docs/ios/use-cocoapods) for Facebook SDK for iOS. |
| 42 | +- [Before You Start](https://developers.facebook.com/docs/ios/getting-started#before-you-start) |
| 43 | +- [Get Your App ID](https://developers.facebook.com/docs/ios/getting-started#app-id) |
| 44 | +- [Get Your Client Token](https://developers.facebook.com/docs/ios/getting-started#client-token) |
| 45 | +- [Step 2: Configure Your Project](https://developers.facebook.com/docs/ios/getting-started#configure-your-project) |
17 | 46 |
|
18 |
| -## Usage |
19 |
| -First of all, you should initialize the LoginManager by calling the `init` method. |
| 47 | +## Use @nativescript/facebook |
| 48 | + |
| 49 | +### Sign in the user |
| 50 | + |
| 51 | +Firstly, initialize the LoginManager by calling the `init` method. |
20 | 52 |
|
21 | 53 | ```ts
|
22 | 54 | import { LoginManager } from '@nativescript/facebook';
|
23 | 55 |
|
24 | 56 | LoginManager.init()
|
25 | 57 | ```
|
26 |
| -Then to log the user in, use the `logInWithPermissions` method. |
27 |
| -You can also use the Login Manager with custom UI to perform Login. |
| 58 | +Next, to sign the user in, call the `logInWithPermissions` method. |
| 59 | +<!-- You can also use the Login Manager with custom UI to perform Login. --> |
| 60 | +<!-- How? 👆🏼 --> |
28 | 61 |
|
29 | 62 | ```ts
|
30 | 63 | import { LoginManager, AccessToken } from '@nativescript/facebook';
|
|
34 | 67 | const accessToken = AccessToken.currentAccessToken();
|
35 | 68 | } catch (e) {}
|
36 | 69 | ```
|
| 70 | +### Sign out the user |
| 71 | + |
| 72 | +To log the user out, call the `logOut` method. |
| 73 | +```ts |
| 74 | +LoginManager.logOut() |
| 75 | +``` |
| 76 | + |
| 77 | +## API |
| 78 | + |
| 79 | +### LoginManager class |
| 80 | + |
| 81 | +The LoginManager class provides the following static methods: |
| 82 | + |
| 83 | +| Method | Returns | Description | |
| 84 | +|------|------|-------------| |
| 85 | +| `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.| |
| 86 | +| `static logInWithPermissions(permissions: string[], context?: any)` | Promise<[LoginResult](#loginresult-class)>| Opens the login window in the optionally provided `context`(a [UIViewController](https://developer.apple.com/documentation/uikit/uiviewcontroller?language=objc) 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. | |
| 87 | +| `static logout()` | `void`| Logs out the user. | |
| 88 | + |
| 89 | +### LoginResult class |
| 90 | +This class provides the login data returned by the `logInWithPermissions` method. |
| 91 | + |
| 92 | +| Name | Type | Description | |
| 93 | +|------|------|-------------| |
| 94 | +| `android` | [LoginManager](https://developers.facebook.com/docs/reference/android/current/class/LoginManager/) |_readonly_. Native instance for Android. | |
| 95 | +| ` ios` |[FBSDKLoginManager](https://developers.facebook.com/docs/reference/ios/current/class/FBSDKLoginManager/)|_readonly_. Native instance for iOS.| |
| 96 | +| `grantedPermissions`|`string[]`| _readonly_| |
| 97 | +| `isCancelled`|`boolean`| _readonly_| |
| 98 | +| `token`| [AccessToken](#accesstoken)| _readonly_| |
| 99 | + |
| 100 | +### AccessToken class |
| 101 | + |
| 102 | +This class provides the data of a Facebook access token. |
| 103 | + |
| 104 | +#### Properties |
| 105 | + |
| 106 | +| Property | Type| Description | |
| 107 | +|------|-----|-------------| |
| 108 | +| `appID` | `string`|| |
| 109 | +| `dataAccessExpirationDate` | `Date`|_readonly_| |
| 110 | +| `dataAccessExpired` | `boolean` | _readonly_| |
| 111 | +| `declinedPermissions`|`string[]`| _readonly_| |
| 112 | +| `expirationDate`| `Date`| _readonly_| |
| 113 | +| `expired`| `boolean`| _readonly_| |
| 114 | +| `expiredPermissions`|`string[]`| _readonly_| |
| 115 | +| `graphDomain` | `string` | _readonly_| |
| 116 | +| `permissions`|`string[]`| _readonly_| |
| 117 | +| `refreshDate`| `Date`| _readonly_| |
| 118 | +| `tokenString` | `string`| _readonly_| |
| 119 | +| `userID` | `string`| _readonly_| |
| 120 | +| `currentAccessTokenIsActive` | `boolean` | _readonly_| |
| 121 | +| `ios` | [FBSDKAccessToken](https://developers.facebook.com/docs/reference/ios/current/class/FBSDKAccessToken/)|_readonly_. iOS access token. | |
| 122 | +| `android` | [AccessToken](https://developers.facebook.com/docs/reference/android/current/class/AccessToken/)|_readonly_. Android access token. | |
| 123 | + |
| 124 | +#### Methods |
| 125 | + |
| 126 | +| Method | Returns |
| 127 | +|:------|:------- |
| 128 | +| `currentAccessToken()` | [AccessToken](#accesstoken-class) | A static method that returns an access token as an instance of the AccessToken class.| |
37 | 129 |
|
38 | 130 | To log the user out, call the `logOut` method.
|
39 | 131 | ```ts
|
|
0 commit comments