UNPKG

9.87 kBTypeScriptView Raw
1export interface FacebookLoginResponse {
2 status: string;
3 authResponse: {
4 session_key: boolean;
5 accessToken: string;
6 expiresIn: number;
7 sig: string;
8 secret: string;
9 userID: string;
10 };
11}
12/**
13 * @name Facebook
14 * @description
15 * Use the Facebook Connect plugin to obtain access to the native FB application on iOS and Android.
16 *
17 * Requires Cordova plugin: `cordova-plugin-facebook4`. For more info, please see the [Facebook Connect](https://github.com/jeduan/cordova-plugin-facebook4).
18 *
19 * #### Installation
20 *
21 * To use the FB plugin, you first have to create a new Facebook App inside of the Facebook developer portal at [https://developers.facebook.com/apps](https://developers.facebook.com/apps).
22 *
23 * [![fb-getstarted-1](/img/docs/native/Facebook/1.png)](https://developers.facebook.com/apps/)
24 *
25 * Retrieve the `App ID` and `App Name`.
26 *
27 * [![fb-getstarted-2](/img/docs/native/Facebook/2.png)](https://developers.facebook.com/apps/)
28 *
29 * Then type in the following command in your Terminal, where APP_ID and APP_NAME are the values from the Facebook Developer portal.
30 *
31 * ```bash
32 * ionic plugin add cordova-plugin-facebook4 --save --variable APP_ID="123456789" --variable APP_NAME="myApplication"
33 * ```
34 *
35 * After, you'll need to add the native platforms you'll be using to your app in the Facebook Developer portal under your app's Settings:
36 *
37 * [![fb-getstarted-3](/img/docs/native/Facebook/3.png)](https://developers.facebook.com/apps/)
38 *
39 * Click `'Add Platform'`.
40 *
41 * [![fb-getstarted-4](/img/docs/native/Facebook/4.png)](https://developers.facebook.com/apps/)
42 *
43 * At this point you'll need to open your project's [`config.xml`](https://cordova.apache.org/docs/en/latest/config_ref/index.html) file, found in the root directory of your project.
44 *
45 * Take note of the `id` for the next step:
46 * ```
47 * <widget id="com.mycompany.testapp" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
48 * ```
49 *
50 * You can also edit the `id` to whatever you'd like it to be.
51 *
52 * #### iOS Install
53 * Under 'Bundle ID', add the `id` from your `config.xml` file:
54 *
55 * [![fb-getstarted-5](/img/docs/native/Facebook/5.png)](https://developers.facebook.com/apps/)
56 *
57 *
58 * #### Android Install
59 * Under 'Google Play Package Name', add the `id` from your `config.xml` file:
60 *
61 * [![fb-getstarted-6](/img/docs/native/Facebook/6.png)](https://developers.facebook.com/apps/)
62 *
63 *
64 * And that's it! You can now make calls to Facebook using the plugin.
65 *
66 * ## Events
67 *
68 * App events allow you to understand the makeup of users engaging with your app, measure the performance of your Facebook mobile app ads, and reach specific sets of your users with Facebook mobile app ads.
69 *
70 * - [iOS] [https://developers.facebook.com/docs/ios/app-events](https://developers.facebook.com/docs/ios/app-events)
71 * - [Android] [https://developers.facebook.com/docs/android/app-events](https://developers.facebook.com/docs/android/app-events)
72 * - [JS] Does not have an Events API, so the plugin functions are empty and will return an automatic success
73 *
74 * Activation events are automatically tracked for you in the plugin.
75 *
76 * Events are listed on the [insights page](https://www.facebook.com/insights/).
77 *
78 * For tracking events, see `logEvent` and `logPurchase`.
79 *
80 * @usage
81 * ```typescript
82 * import { Facebook } from 'ionic-native';
83 *
84 *
85 *
86 * ```
87 *
88 */
89export declare class Facebook {
90 /**
91 * Browser wrapper
92 * @param {number} appId Your Facebook AppID from their dashboard
93 * @param {string} version The version of API you may want to use. Optional
94 * @returns {Promise<any>}
95 */
96 static browserInit(appId: number, version?: string): Promise<any>;
97 /**
98 * Login to Facebook to authenticate this app.
99 *
100 * ```typescript
101 * {
102 * status: "connected",
103 * authResponse: {
104 * session_key: true,
105 * accessToken: "kgkh3g42kh4g23kh4g2kh34g2kg4k2h4gkh3g4k2h4gk23h4gk2h34gk234gk2h34AndSoOn",
106 * expiresIn: 5183979,
107 * sig: "...",
108 * secret: "...",
109 * userID: "634565435"
110 * }
111 * }
112 * ```
113 *
114 * @param {string[]} permissions List of [permissions](https://developers.facebook.com/docs/facebook-login/permissions) this app has upon logging in.
115 * @returns {Promise<FacebookLoginResponse>} Returns a Promise that resolves with a status object if login succeeds, and rejects if login fails.
116 */
117 static login(permissions: string[]): Promise<FacebookLoginResponse>;
118 /**
119 * Logout of Facebook.
120 *
121 * For more info see the [Facebook docs](https://developers.facebook.com/docs/reference/javascript/FB.logout)
122 * @returns {Promise<any>} Returns a Promise that resolves on a successful logout, and rejects if logout fails.
123 */
124 static logout(): Promise<any>;
125 /**
126 * Determine if a user is logged in to Facebook and has authenticated your app. There are three possible states for a user:
127 *
128 * 1) the user is logged into Facebook and has authenticated your application (connected)
129 * 2) the user is logged into Facebook but has not authenticated your application (not_authorized)
130 * 3) the user is either not logged into Facebook or explicitly logged out of your application so it doesn't attempt to connect to Facebook and thus, we don't know if they've authenticated your application or not (unknown)
131 *
132 * Resolves with a response like:
133 *
134 * ```
135 * {
136 * authResponse: {
137 * userID: "12345678912345",
138 * accessToken: "kgkh3g42kh4g23kh4g2kh34g2kg4k2h4gkh3g4k2h4gk23h4gk2h34gk234gk2h34AndSoOn",
139 * session_Key: true,
140 * expiresIn: "5183738",
141 * sig: "..."
142 * },
143 * status: "connected"
144 * }
145 * ```
146 *
147 * For more information see the [Facebook docs](https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus)
148 *
149 * @returns {Promise<any>} Returns a Promise that resolves with a status, or rejects with an error
150 */
151 static getLoginStatus(): Promise<any>;
152 /**
153 * Get a Facebook access token for using Facebook services.
154 *
155 * @returns {Promise<string>} Returns a Promise that resolves with an access token, or rejects with an error
156 */
157 static getAccessToken(): Promise<string>;
158 /**
159 * Show one of various Facebook dialogs. Example of options for a Share dialog:
160 *
161 * ```
162 * {
163 * method: "share",
164 * href: "http://example.com",
165 * caption: "Such caption, very feed.",
166 * description: "Much description",
167 * picture: 'http://example.com/image.png'
168 * }
169 * ```
170 *
171 * For more options see the [Cordova plugin docs](https://github.com/jeduan/cordova-plugin-facebook4#show-a-dialog) and the [Facebook docs](https://developers.facebook.com/docs/javascript/reference/FB.ui)
172 * @param {Object} options The dialog options
173 * @returns {Promise<any>} Returns a Promise that resolves with success data, or rejects with an error
174 */
175 static showDialog(options: any): Promise<any>;
176 /**
177 * Make a call to Facebook Graph API. Can take additional permissions beyond those granted on login.
178 *
179 * For more information see:
180 *
181 * Calling the Graph API - https://developers.facebook.com/docs/javascript/reference/FB.api
182 * Graph Explorer - https://developers.facebook.com/tools/explorer
183 * Graph API - https://developers.facebook.com/docs/graph-api
184 *
185 * @param {string} requestPath Graph API endpoint you want to call
186 * @param {string[]} permissions List of [permissions](https://developers.facebook.com/docs/facebook-login/permissions) for this request.
187 * @returns {Promise<any>} Returns a Promise that resolves with the result of the request, or rejects with an error
188 */
189 static api(requestPath: string, permissions: string[]): Promise<any>;
190 /**
191 * Log an event. For more information see the Events section above.
192 *
193 * @param {string} name Name of the event
194 * @param {Object} [params] An object containing extra data to log with the event
195 * @param {number} [valueToSum] any value to be added to added to a sum on each event
196 * @returns {Promise<any>}
197 */
198 static logEvent(name: string, params?: Object, valueToSum?: number): Promise<any>;
199 /**
200 * Log a purchase. For more information see the Events section above.
201 *
202 * @param {number} value Value of the purchase.
203 * @param {string} currency The currency, as an [ISO 4217 currency code](http://en.wikipedia.org/wiki/ISO_4217)
204 * @returns {Promise<any>}
205 */
206 static logPurchase(value: number, currency: string): Promise<any>;
207 /**
208 * Open App Invite dialog. Does not require login.
209 *
210 * For more information see:
211 *
212 * the App Invites Overview - https://developers.facebook.com/docs/app-invites/overview
213 * the App Links docs - https://developers.facebook.com/docs/applinks
214 *
215 *
216 * @param {Object} options An object containing an [App Link](https://developers.facebook.com/docs/applinks) URL to your app and an optional image URL.
217 * url: [App Link](https://developers.facebook.com/docs/applinks) to your app
218 * picture: image to be displayed in the App Invite dialog
219 *
220 * @returns {Promise<any>} Returns a Promise that resolves with the result data, or rejects with an error
221 */
222 static appInvite(options: {
223 url: string;
224 picture: string;
225 }): Promise<any>;
226}