UNPKG

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