UNPKG

14.3 kBTypeScriptView Raw
1import { IonicNativePlugin } from '@ionic-native/core';
2export interface FacebookLoginResponse {
3 status: string;
4 authResponse: {
5 accessToken: string;
6 data_access_expiration_time: string;
7 expiresIn: number;
8 userID: string;
9 };
10}
11/**
12 * @name Facebook
13 * @description
14 * Use the Facebook Connect plugin to obtain access to the native FB application on iOS and Android.
15 *
16 * Requires Cordova plugin: `cordova-plugin-facebook-connect`. For more info, please see the [Facebook Connect](https://github.com/cordova-plugin-facebook-connect/cordova-plugin-facebook-connect).
17 *
18 * #### Installation
19 *
20 * 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).
21 *
22 * [![fb-getstarted-1](/img/docs/native/Facebook/1.png)](https://developers.facebook.com/apps/)
23 *
24 * Retrieve the `App ID` and `App Name`.
25 *
26 * [![fb-getstarted-2](/img/docs/native/Facebook/2.png)](https://developers.facebook.com/apps/)
27 *
28 * Then type in the following command in your Terminal, where APP_ID and APP_NAME are the values from the Facebook Developer portal.
29 *
30 * ```bash
31 * ionic cordova plugin add cordova-plugin-facebook-connect --variable APP_ID="123456789" --variable APP_NAME="myApplication"
32 * ```
33 *
34 * 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:
35 *
36 * [![fb-getstarted-3](/img/docs/native/Facebook/3.png)](https://developers.facebook.com/apps/)
37 *
38 * Click `'Add Platform'`.
39 *
40 * [![fb-getstarted-4](/img/docs/native/Facebook/4.png)](https://developers.facebook.com/apps/)
41 *
42 * 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.
43 *
44 * Take note of the `id` for the next step:
45 * ```
46 * <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">
47 * ```
48 *
49 * You can also edit the `id` to whatever you'd like it to be.
50 *
51 * #### iOS Install
52 * Under 'Bundle ID', add the `id` from your `config.xml` file:
53 *
54 * [![fb-getstarted-5](/img/docs/native/Facebook/5.png)](https://developers.facebook.com/apps/)
55 *
56 *
57 * #### Android Install
58 * Under 'Google Play Package Name', add the `id` from your `config.xml` file:
59 *
60 * [![fb-getstarted-6](/img/docs/native/Facebook/6.png)](https://developers.facebook.com/apps/)
61 *
62 *
63 * And that's it! You can now make calls to Facebook using the plugin.
64 *
65 * ## Events
66 *
67 * 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.
68 *
69 * - [iOS] [https://developers.facebook.com/docs/ios/app-events](https://developers.facebook.com/docs/ios/app-events)
70 * - [Android] [https://developers.facebook.com/docs/android/app-events](https://developers.facebook.com/docs/android/app-events)
71 * - [JS] Does not have an Events API, so the plugin functions are empty and will return an automatic success
72 *
73 * Activation events are automatically tracked for you in the plugin.
74 *
75 * Events are listed on the [insights page](https://www.facebook.com/insights/).
76 *
77 * For tracking events, see `logEvent` and `logPurchase`.
78 *
79 * @usage
80 * ```typescript
81 * import { Facebook, FacebookLoginResponse } from '@ionic-native/facebook/ngx';
82 *
83 * constructor(private fb: Facebook) { }
84 *
85 * ...
86 *
87 * this.fb.login(['public_profile', 'user_friends', 'email'])
88 * .then((res: FacebookLoginResponse) => console.log('Logged into Facebook!', res))
89 * .catch(e => console.log('Error logging into Facebook', e));
90 *
91 *
92 * this.fb.logEvent(this.fb.EVENTS.EVENT_NAME_ADDED_TO_CART);
93 *
94 * ```
95 *
96 */
97export declare class FacebookOriginal extends IonicNativePlugin {
98 EVENTS: {
99 EVENT_NAME_ACTIVATED_APP: string;
100 EVENT_NAME_DEACTIVATED_APP: string;
101 EVENT_NAME_SESSION_INTERRUPTIONS: string;
102 EVENT_NAME_TIME_BETWEEN_SESSIONS: string;
103 EVENT_NAME_COMPLETED_REGISTRATION: string;
104 EVENT_NAME_VIEWED_CONTENT: string;
105 EVENT_NAME_SEARCHED: string;
106 EVENT_NAME_RATED: string;
107 EVENT_NAME_COMPLETED_TUTORIAL: string;
108 EVENT_NAME_PUSH_TOKEN_OBTAINED: string;
109 EVENT_NAME_ADDED_TO_CART: string;
110 EVENT_NAME_ADDED_TO_WISHLIST: string;
111 EVENT_NAME_INITIATED_CHECKOUT: string;
112 EVENT_NAME_ADDED_PAYMENT_INFO: string;
113 EVENT_NAME_PURCHASED: string;
114 EVENT_NAME_ACHIEVED_LEVEL: string;
115 EVENT_NAME_UNLOCKED_ACHIEVEMENT: string;
116 EVENT_NAME_SPENT_CREDITS: string;
117 EVENT_PARAM_CURRENCY: string;
118 EVENT_PARAM_REGISTRATION_METHOD: string;
119 EVENT_PARAM_CONTENT_TYPE: string;
120 EVENT_PARAM_CONTENT_ID: string;
121 EVENT_PARAM_SEARCH_STRING: string;
122 EVENT_PARAM_SUCCESS: string;
123 EVENT_PARAM_MAX_RATING_VALUE: string;
124 EVENT_PARAM_PAYMENT_INFO_AVAILABLE: string;
125 EVENT_PARAM_NUM_ITEMS: string;
126 EVENT_PARAM_LEVEL: string;
127 EVENT_PARAM_DESCRIPTION: string;
128 EVENT_PARAM_SOURCE_APPLICATION: string;
129 EVENT_PARAM_VALUE_YES: string;
130 EVENT_PARAM_VALUE_NO: string;
131 };
132 /**
133 * Get the current application ID
134 *
135 * @returns {Promise<string>} Returns a Promise that resolves with the current application ID
136 */
137 getApplicationId(): Promise<string>;
138 /**
139 * Set the application ID
140 *
141 * @param {string} id application ID
142 */
143 setApplicationId(id: string): Promise<void>;
144 /**
145 * Get the current application name
146 *
147 * @returns {Promise<string>} Returns a Promise that resolves with the current application name
148 */
149 getApplicationName(): Promise<string>;
150 /**
151 * Set the application name
152 *
153 * @param {string} name application name
154 */
155 setApplicationName(name: string): Promise<void>;
156 /**
157 * Login to Facebook to authenticate this app.
158 *
159 * ```typescript
160 * {
161 * status: 'connected',
162 * authResponse: {
163 * accessToken: 'kgkh3g42kh4g23kh4g2kh34g2kg4k2h4gkh3g4k2h4gk23h4gk2h34gk234gk2h34AndSoOn',
164 * data_access_expiration_time: '1623680244',
165 * expiresIn: 5183979,
166 * userID: '634565435'
167 * }
168 * }
169 *
170 * ```
171 *
172 * @param {string[]} permissions List of [permissions](https://developers.facebook.com/docs/facebook-login/permissions) this app has upon logging in.
173 * @returns {Promise<FacebookLoginResponse>} Returns a Promise that resolves with a status object if login succeeds, and rejects if login fails.
174 */
175 login(permissions: string[]): Promise<FacebookLoginResponse>;
176 /**
177 * Login to Facebook using Limited Login (iOS Only)
178 *
179 * ```typescript
180 * {
181 * status: 'connected',
182 * authResponse: {
183 * authenticationToken: 'kgkh3g42kh4g23kh4g2kh34g2kg4k2h4gkh3g4k2h4gk23h4gk2h34gk234gk2h34AndSoOn',
184 * nonce: 'foo',
185 * userID: '634565435'
186 * }
187 * }
188 *
189 * ```
190 *
191 * @param {string[]} permissions List of [permissions](https://developers.facebook.com/docs/facebook-login/limited-login/permissions) this app has upon logging in.
192 * @returns {Promise<FacebookLoginResponse>} Returns a Promise that resolves with a status object if login succeeds, and rejects if login fails.
193 */
194 loginWithLimitedTracking(permissions: string[]): Promise<FacebookLoginResponse>;
195 /**
196 * Check if the user has approved all necessary permissions
197 *
198 * @param {string[]} permissions List of [permissions](https://developers.facebook.com/docs/facebook-login/permissions) to check for
199 * @returns {Promise<string>} Returns a Promise that resolves with a success string if all passed permissions are granted, or an error string if any permissions are not granted
200 */
201 checkHasCorrectPermissions(permissions: string[]): Promise<string>;
202 /**
203 * Check if data access has expired for the user
204 *
205 * @returns {Promise<string>} Returns a Promise that resolves with a success string if data access is expired, or rejects with an error
206 */
207 isDataAccessExpired(): Promise<string>;
208 /**
209 * Reauthorize data access after it has expired
210 *
211 * @returns {Promise<FacebookLoginResponse>} Returns a Promise that resolves with a status object if login succeeds, and rejects if login fails.
212 */
213 reauthorizeDataAccess(): Promise<FacebookLoginResponse>;
214 /**
215 * Logout of Facebook.
216 *
217 * For more info see the [Facebook docs](https://developers.facebook.com/docs/reference/javascript/FB.logout)
218 * @returns {Promise<any>} Returns a Promise that resolves on a successful logout, and rejects if logout fails.
219 */
220 logout(): Promise<any>;
221 /**
222 * Determine if a user is logged in to Facebook and has authenticated your app. There are three possible states for a user:
223 *
224 * 1) the user is logged into Facebook and has authenticated your application (connected)
225 * 2) the user is logged into Facebook but has not authenticated your application (not_authorized)
226 * 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)
227 *
228 * Resolves with a response like:
229 *
230 * ```
231 * {
232 * authResponse: {
233 * userID: '12345678912345',
234 * accessToken: 'kgkh3g42kh4g23kh4g2kh34g2kg4k2h4gkh3g4k2h4gk23h4gk2h34gk234gk2h34AndSoOn',
235 * data_access_expiration_time: '1623680244',
236 * expiresIn: '5183738'
237 * },
238 * status: 'connected'
239 * }
240 * ```
241 *
242 * For more information see the [Facebook docs](https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus)
243 *
244 * @returns {Promise<any>} Returns a Promise that resolves with a status, or rejects with an error
245 */
246 getLoginStatus(): Promise<any>;
247 /**
248 * Get a Facebook access token for using Facebook services.
249 *
250 * @returns {Promise<string>} Returns a Promise that resolves with an access token, or rejects with an error
251 */
252 getAccessToken(): Promise<string>;
253 /**
254 * Get profile information for the currently logged in user
255 *
256 * @returns {Promise<any>} Returns a Promise that resolves with success data, or rejects with an error
257 */
258 getCurrentProfile(): Promise<any>;
259 /**
260 * Show one of various Facebook dialogs. Example of options for a Share dialog:
261 *
262 * ```
263 * {
264 * method: 'share',
265 * href: 'http://example.com',
266 * caption: 'Such caption, very feed.',
267 * description: 'Much description',
268 * picture: 'http://example.com/image.png'
269 * }
270 * ```
271 *
272 * For more options see the [Cordova plugin docs](https://github.com/cordova-plugin-facebook-connect/cordova-plugin-facebook-connect#show-a-dialog) and the [Facebook docs](https://developers.facebook.com/docs/javascript/reference/FB.ui)
273 * @param {Object} options The dialog options
274 * @returns {Promise<any>} Returns a Promise that resolves with success data, or rejects with an error
275 */
276 showDialog(options: any): Promise<any>;
277 /**
278 * Make a call to Facebook Graph API. Can take additional permissions beyond those granted on login.
279 *
280 * For more information see:
281 *
282 * Calling the Graph API - https://developers.facebook.com/docs/javascript/reference/FB.api
283 * Graph Explorer - https://developers.facebook.com/tools/explorer
284 * Graph API - https://developers.facebook.com/docs/graph-api
285 *
286 * @param {string} requestPath Graph API endpoint you want to call
287 * @param {string[]} permissions List of [permissions](https://developers.facebook.com/docs/facebook-login/permissions) for this request.
288 * @param {string} httpMethod HTTP method for the request, one of "GET", "POST", or "DELETE" (default is "GET")
289 * @returns {Promise<any>} Returns a Promise that resolves with the result of the request, or rejects with an error
290 */
291 api(requestPath: string, permissions: string[], httpMethod?: string): Promise<any>;
292 /**
293 * Log an event. For more information see the Events section above.
294 *
295 * @param {string} name Name of the event
296 * @param {Object} [params] An object containing extra data to log with the event
297 * @param {number} [valueToSum] any value to be added to added to a sum on each event
298 * @returns {Promise<any>}
299 */
300 logEvent(name: string, params?: Object, valueToSum?: number): Promise<any>;
301 /**
302 * Enable or disable the auto log app event feature - https://developers.facebook.com/docs/app-events/gdpr-compliance/
303 *
304 * @param {boolean} enabled value to be set
305 */
306 setAutoLogAppEventsEnabled(enabled: boolean): Promise<void>;
307 /**
308 * Enable or disable collection of advertiser-id
309 *
310 * @param {boolean} enabled value to be set
311 */
312 setAdvertiserIDCollectionEnabled(enabled: boolean): Promise<void>;
313 /**
314 * Enable or disable advertiser tracking (iOS Only)
315 *
316 * @param {boolean} enabled value to be set
317 */
318 setAdvertiserTrackingEnabled(enabled: boolean): Promise<void>;
319 /**
320 * Log a purchase. For more information see the Events section above.
321 *
322 * @param {number} value Value of the purchase.
323 * @param {string} currency The currency, as an [ISO 4217 currency code](http://en.wikipedia.org/wiki/ISO_4217)
324 * @param {Object} params An object containing extra data to log with the event
325 * @returns {Promise<any>}
326 */
327 logPurchase(value: number, currency: string, params?: Object): Promise<any>;
328 /**
329 * Returns the deferred app link
330 * @returns {Promise<any>}
331 */
332 getDeferredApplink(): Promise<string>;
333 /**
334 * Manually log activation events
335 * @returns {Promise<any>}
336 */
337 activateApp(): Promise<any>;
338}
339
340export declare const Facebook: FacebookOriginal;
\No newline at end of file