2015-12-01 12:15:21 +08:00
import { Plugin , Cordova } from './plugin' ;
2016-02-13 08:06:42 +08:00
/ * *
2016-02-23 05:20:00 +08:00
* @name Facebook
* @description
2016-02-13 08:06:42 +08:00
* Use the Facebook Connect plugin to obtain access to the native FB application on iOS and Android .
*
* Requires Cordova plugin : ` cordova-plugin-facebook4 ` . For more info , please see the [ Facebook Connect ] ( https : //github.com/jeduan/cordova-plugin-facebook4).
*
* # # # # Installation
*
* 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).
*
* [ ! [ fb - getstarted - 1 ] ( / i m g / d o c s / n a t i v e / F a c e b o o k / 1 . p n g ) ] ( h t t p s : / / d e v e l o p e r s . f a c e b o o k . c o m / a p p s / )
*
* Retrieve the ` App ID ` and ` App Name ` .
*
* [ ! [ fb - getstarted - 2 ] ( / i m g / d o c s / n a t i v e / F a c e b o o k / 2 . p n g ) ] ( h t t p s : / / d e v e l o p e r s . f a c e b o o k . c o m / a p p s / )
*
* Then type in the following command in your Terminal , where APP_ID and APP_NAME are the values from the Facebook Developer portal .
*
* ` ` ` bash
* cordova plugin add cordova - plugin - facebook4 -- save -- variable APP_ID = "123456789" -- variable APP_NAME = "myApplication"
* ` ` `
*
* 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 :
*
* [ ! [ fb - getstarted - 3 ] ( / i m g / d o c s / n a t i v e / F a c e b o o k / 3 . p n g ) ] ( h t t p s : / / d e v e l o p e r s . f a c e b o o k . c o m / a p p s / )
*
* Click ` 'Add Platform' ` .
*
* [ ! [ fb - getstarted - 4 ] ( / i m g / d o c s / n a t i v e / F a c e b o o k / 4 . p n g ) ] ( h t t p s : / / d e v e l o p e r s . f a c e b o o k . c o m / a p p s / )
*
* 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.
*
* Take note of the ` id ` for the next step :
* ` ` `
* < 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" >
* ` ` `
*
* You can also edit the ` id ` to whatever you ' d like it to be .
*
* # # # # iOS Install
* Under 'Bundle ID' , add the ` id ` from your ` config.xml ` file :
*
* [ ! [ fb - getstarted - 5 ] ( / i m g / d o c s / n a t i v e / F a c e b o o k / 5 . p n g ) ] ( h t t p s : / / d e v e l o p e r s . f a c e b o o k . c o m / a p p s / )
*
*
* # # # # Android Install
* Under 'Google Play Package Name' , add the ` id ` from your ` config.xml ` file :
*
* [ ! [ fb - getstarted - 6 ] ( / i m g / d o c s / n a t i v e / F a c e b o o k / 6 . p n g ) ] ( h t t p s : / / d e v e l o p e r s . f a c e b o o k . c o m / a p p s / )
*
*
* And that ' s it ! You can now make calls to Facebook using the plugin .
*
* # # Events
*
* 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 .
*
* - [ iOS ] [ https : //developers.facebook.com/docs/ios/app-events](https://developers.facebook.com/docs/ios/app-events)
* - [ Android ] [ https : //developers.facebook.com/docs/android/app-events](https://developers.facebook.com/docs/android/app-events)
* - [ JS ] Does not have an Events API , so the plugin functions are empty and will return an automatic success
*
* Activation events are automatically tracked for you in the plugin .
*
* Events are listed on the [ insights page ] ( https : //www.facebook.com/insights/).
*
* For tracking events , see ` logEvent ` and ` logPurchase ` .
*
2016-03-25 01:00:18 +08:00
* @usage
* ` ` ` js
* import { Facebook } from 'ionic-native' ;
*
*
*
* ` ` `
*
2016-02-13 08:06:42 +08:00
* /
2015-12-01 12:15:21 +08:00
@Plugin ( {
plugin : 'cordova-plugin-facebook4' ,
2016-02-23 05:20:00 +08:00
pluginRef : 'facebookConnectPlugin' ,
2016-03-29 13:57:53 +08:00
repo : 'https://github.com/jeduan/cordova-plugin-facebook4' ,
install : 'cordova plugin add cordova-plugin-facebook4 --variable APP_ID="123456789" --variable APP_NAME="myApplication"'
2015-12-01 12:15:21 +08:00
} )
export class Facebook {
2016-02-13 08:06:42 +08:00
// @Cordova()
// static browserInit(appId: number){
// return new Promise<any>((res, rej) => {});
// }
/ * *
* Login to Facebook to authenticate this app .
*
2016-02-23 05:20:00 +08:00
* ` ` ` ts
2016-02-13 08:06:42 +08:00
* {
* status : "connected" ,
* authResponse : {
* session_key : true ,
* accessToken : "kgkh3g42kh4g23kh4g2kh34g2kg4k2h4gkh3g4k2h4gk23h4gk2h34gk234gk2h34AndSoOn" ,
* expiresIn : 5183979 ,
* sig : "..." ,
* secret : "..." ,
* userID : "634565435"
* }
* }
* ` ` `
*
* @param { string [ ] } permissions List of [ permissions ] ( https : //developers.facebook.com/docs/facebook-login/permissions) this app has upon logging in.
* @return Returns a Promise that resolves with a status object if login succeeds , and rejects if login fails .
* /
2015-12-01 12:15:21 +08:00
@Cordova ( )
2016-03-11 05:48:20 +08:00
static login ( permissions : string [ ] ) : Promise < any > { return }
2015-12-01 12:15:21 +08:00
2016-02-13 08:06:42 +08:00
/ * *
* Logout of Facebook .
*
* For more info see the [ Facebook docs ] ( https : //developers.facebook.com/docs/reference/javascript/FB.logout)
* @return Returns a Promise that resolves on a successful logout , and rejects if logout fails .
* /
2015-12-01 12:15:21 +08:00
@Cordova ( )
2016-03-11 05:48:20 +08:00
static logout ( ) : Promise < any > { return }
2015-12-01 12:15:21 +08:00
2016-02-13 08:06:42 +08:00
/ * *
* Determine if a user is logged in to Facebook and has authenticated your app . There are three possible states for a user :
*
* 1 ) the user is logged into Facebook and has authenticated your application ( connected )
* 2 ) the user is logged into Facebook but has not authenticated your application ( not_authorized )
* 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 )
*
* Resolves with a response like :
*
* ` ` `
* {
* authResponse : {
* userID : "12345678912345" ,
* accessToken : "kgkh3g42kh4g23kh4g2kh34g2kg4k2h4gkh3g4k2h4gk23h4gk2h34gk234gk2h34AndSoOn" ,
* session_Key : true ,
* expiresIn : "5183738" ,
* sig : "..."
* } ,
* status : "connected"
* }
* ` ` `
*
* For more information see the [ Facebook docs ] ( https : //developers.facebook.com/docs/reference/javascript/FB.getLoginStatus)
*
* @return Returns a Promise that resolves with a status , or rejects with an error
* /
2015-12-01 12:15:21 +08:00
@Cordova ( )
2016-03-11 05:48:20 +08:00
static getLoginStatus ( ) : Promise < any > { return }
2015-12-01 12:15:21 +08:00
2016-02-13 08:06:42 +08:00
/ * *
* Get a Facebook access token for using Facebook services .
*
* @return Returns a Promise that resolves with an access token , or rejects with an error
* /
2015-12-01 12:15:21 +08:00
@Cordova ( )
2016-03-11 05:48:20 +08:00
static getAccessToken ( ) : Promise < string > { return }
2015-12-01 12:15:21 +08:00
2016-02-13 08:06:42 +08:00
/ * *
* Show one of various Facebook dialogs . Example of options for a Share dialog :
*
* ` ` `
* {
* method : "share" ,
* href : "http://example.com" ,
* caption : "Such caption, very feed." ,
* description : "Much description" ,
* picture : 'http://example.com/image.png'
* }
* ` ` `
*
* 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)
* @options { Object } options The dialog options
* @return Returns a Promise that resolves with success data , or rejects with an error
* /
2015-12-01 12:15:21 +08:00
@Cordova ( )
2016-03-11 05:48:20 +08:00
static showDialog ( options : any ) : Promise < any > { return }
2015-12-01 12:15:21 +08:00
2016-02-13 08:06:42 +08:00
/ * *
* Make a call to Facebook Graph API . Can take additional permissions beyond those granted on login .
*
* For more information see :
*
* Calling the Graph API - https : //developers.facebook.com/docs/javascript/reference/FB.api
* Graph Explorer - https : //developers.facebook.com/tools/explorer
* Graph API - https : //developers.facebook.com/docs/graph-api
*
* @param { string } requestPath Graph API endpoint you want to call
* @param { string [ ] } permissions List of [ permissions ] ( https : //developers.facebook.com/docs/facebook-login/permissions) for this request.
* @return Returns a Promise that resolves with the result of the request , or rejects with an error
* /
2015-12-01 12:15:21 +08:00
@Cordova ( )
2016-03-11 05:48:20 +08:00
static api ( requestPath : string , permissions : string [ ] ) : Promise < any > { return }
2015-12-01 12:15:21 +08:00
2016-02-13 08:06:42 +08:00
/ * *
* Log an event . For more information see the Events section above .
*
* @param { string } name Name of the event
* @param { Object } [ params ] An object containing extra data to log with the event
* @param { number } [ valueToSum ] any value to be added to added to a sum on each event
* @return
* /
2015-12-01 12:15:21 +08:00
@Cordova ( )
2016-03-11 05:48:20 +08:00
static logEvent (
name : string ,
params? : Object ,
valueToSum? : number
) : Promise < any > { return }
2015-12-01 12:15:21 +08:00
2016-02-13 08:06:42 +08:00
/ * *
* Log a purchase . For more information see the Events section above .
*
* @param { number } value Value of the purchase .
* @param { string } currency The currency , as an [ ISO 4217 currency code ] ( http : //en.wikipedia.org/wiki/ISO_4217)
* @return Returns a Promise
* /
2015-12-01 12:15:21 +08:00
@Cordova ( )
2016-03-11 05:48:20 +08:00
static logPurchase ( value : number , currency : string ) : Promise < any > { return }
2015-12-01 12:15:21 +08:00
2016-02-13 08:06:42 +08:00
/ * *
* Open App Invite dialog . Does not require login .
*
* For more information see :
*
* the App Invites Overview - https : //developers.facebook.com/docs/app-invites/overview
* the App Links docs - https : //developers.facebook.com/docs/applinks
*
*
* @param { Object } options An object containing an [ App Link ] ( https : //developers.facebook.com/docs/applinks) URL to your app and an optional image URL.
* url : [ App Link ] ( https : //developers.facebook.com/docs/applinks) to your app
* picture : image to be displayed in the App Invite dialog
*
* @return Returns a Promise that resolves with the result data , or rejects with an error
* /
2015-12-01 12:15:21 +08:00
@Cordova ( )
2016-02-13 08:06:42 +08:00
static appInvite ( options : {
url : string ,
picture : string
2016-03-11 05:48:20 +08:00
} ) : Promise < any > { return }
2015-12-01 12:15:21 +08:00
}