![Introducing Enhanced Alert Actions and Triage Functionality](https://cdn.sanity.io/images/cgdhsj6q/production/fe71306d515f85de6139b46745ea7180362324f0-2530x946.png?w=800&fit=max&auto=format)
Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
cordova-plugin-facebook-connect
Advanced tools
Changelog
2.0.0 (2021-02-25)
browserInit
method on the browser platform; this method which was previously a no-op is no longer defined (closes #26)login
method to remove unnecessary checks for read/publish permissions; the plugin will no longer prevent developers from requesting read and publish permissions at the same time, and will rely on the Facebook SDK's own internal logic instead (closes #34)showDialog
method to remove the deprecated caption, description, and picture properties (closes #28)setAdvertiserTrackingEnabled
method to allow for enabling advertiser tracking on iOS 14+getAccessToken
method to be consistent on all platforms and return the error message "Session not open." if the user has no current access tokenlogout
method to be consistent on all platforms and call the success callback even if the user has no current access token (closes #20)<a name="1.2.1"></a>
Readme
Use Facebook SDK in Cordova projects
See npm package for versions - https://www.npmjs.com/package/cordova-plugin-facebook-connect
Make sure you've registered your Facebook app with Facebook and have an APP_ID
https://developers.facebook.com/apps.
$ cordova plugin add cordova-plugin-facebook-connect --save --variable APP_ID="123456789" --variable APP_NAME="myApplication"
As the APP_NAME
is used as a string in XML files, if your app name contains any special characters like "&", make sure you escape them, e.g. "&".
If you need to change your APP_ID
after installation, it's recommended that you remove and then re-add the plugin as above. Note that changes to the APP_ID
value in your config.xml
file will not be propagated to the individual platform builds.
This is a fork of the official plugin for Facebook in Apache Cordova that implements the latest Facebook SDK. Unless noted, this is a drop-in replacement. You don't have to replace your client code.
The Facebook plugin for Apache Cordova allows you to use the same JavaScript code in your Cordova application as you use in your web application.
If you are looking to test the plugin, would like to reproduce a bug or build issues, there is a demo project for such purpose: cordova-plugin-facebook-connect-lab.
This plugin use the SDKs provided by Facebook. More information about these in their documentation for iOS or Android
This plugin will always be released for iOS and for Android with a synchronized usage of the Facebook SDKs.
Please note that this plugin itself does not specify which Graph API version is used. The Graph API version is set by the Facebook SDK for iOS and Android (see Facebook documentation about versioning)
facebookConnectPlugin.login(Array strings of permissions, Function success, Function failure)
Success function returns an Object like:
{
status: "connected",
authResponse: {
session_key: true,
accessToken: "<long string>",
expiresIn: 5183979,
sig: "...",
secret: "...",
userID: "634565435"
}
}
Failure function returns an error String.
facebookConnectPlugin.logout(Function success, Function failure)
facebookConnectPlugin.checkHasCorrectPermissions(Array strings of permissions, Function success, Function failure)
Success function returns a success string if all passed permissions are granted.
Failure function returns an error String if any passed permissions are not granted.
facebookConnectPlugin.getLoginStatus(Function success, Function failure)
Success function returns an Object like:
{
authResponse: {
userID: "12345678912345",
accessToken: "kgkh3g42kh4g23kh4g2kh34g2kg4k2h4gkh3g4k2h4gk23h4gk2h34gk234gk2h34AndSoOn",
session_Key: true,
expiresIn: "5183738",
sig: "..."
},
status: "connected"
}
For more information see: Facebook Documentation
facebookConnectPlugin.showDialog(Object options, Function success, Function failure)
Example options - Share Dialog:
{
method: "share",
href: "http://example.com",
hashtag: '#myHashtag',
share_feedWeb: true, // iOS only
}
The default dialog mode is FBSDKShareDialogModeAutomatic
. You can share that by adding a specific dialog mode parameter. The available share dialog modes are: share_sheet
, share_feedBrowser
, share_native
and share_feedWeb
. Read more about share dialog modes
Game request:
{
method: "apprequests",
message: "Come on man, check out my application.",
data: data,
title: title,
actionType: 'askfor',
objectID: 'YOUR_OBJECT_ID',
filters: 'app_non_users'
}
Send Dialog:
{
method: "send",
link: "http://example.com"
}
For options information see: Facebook share dialog documentation Facebook send dialog documentation
Success function returns an Object with postId
as String or from
and to
information when doing apprequest
.
Failure function returns an error String.
facebookConnectPlugin.api(String requestPath, Array permissions, String httpMethod, Function success, Function failure)
Allows access to the Facebook Graph API. This API allows for additional permission because, unlike login, the Graph API can accept multiple permissions.
Example permissions:
["public_profile", "user_birthday"]
httpMethod
is optional and defaults to "GET".
Success function returns an Object.
Failure function returns an error String.
Note: "In order to make calls to the Graph API on behalf of a user, the user has to be logged into your app using Facebook login."
For more information see:
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.
Activation events are automatically tracked for you in the plugin.
Events are listed on the insights page
logEvent(String name, Object params, Number valueToSum, Function success, Function failure)
logPurchase(Number value, String currency, Object params, Function success, Function failure)
NOTE: Both value
and currency
are required. The currency specification is expected to be an ISO 4217 currency code. params
is optional.
activateApp(Function success, Function failure)
In your onDeviceReady
event add the following
var fbLoginSuccess = function (userData) {
console.log("UserInfo: ", userData);
}
facebookConnectPlugin.login(["public_profile"], fbLoginSuccess,
function loginError (error) {
console.error(error)
}
);
If you need the Facebook access token (for example, for validating the login on server side), do:
var fbLoginSuccess = function (userData) {
console.log("UserInfo: ", userData);
facebookConnectPlugin.getAccessToken(function(token) {
console.log("Token: " + token);
});
}
facebookConnectPlugin.login(["public_profile"], fbLoginSuccess,
function (error) {
console.error(error)
}
);
For a more instructive example change the above fbLoginSuccess
to;
var fbLoginSuccess = function (userData) {
console.log("UserInfo: ", userData);
facebookConnectPlugin.getLoginStatus(function onLoginStatus (status) {
console.log("current status: ", status);
facebookConnectPlugin.showDialog({
method: "share"
}, function onShareSuccess (result) {
console.log("Posted. ", result);
});
});
};
Using the graph api this is a very simple task:
facebookConnectPlugin.api("<user-id>/?fields=id,email", ["user_birthday"],
function onSuccess (result) {
console.log("Result: ", result);
/* logs:
{
"id": "000000123456789",
"email": "myemail@example.com"
}
*/
}, function onError (error) {
console.error("Failed: ", error);
}
);
Send a photo to a user's feed
facebookConnectPlugin.showDialog({
method: "share",
name:'Test Post',
message:'First photo post'
}, function (response) {
console.log(response)
}, function (response) {
console.log(response)
}
);
Starting from Facebook SDK v4.34 for both iOS and Android, there is a new way of converting pixel events into mobile app events. For more information: https://developers.facebook.com/docs/app-events/hybrid-app-events/
In order to enable this feature in your Cordova app, please set the FACEBOOK_HYBRID_APP_EVENTS variable to "true" (default is false):
$ cordova plugin add cordova-plugin-facebook-connect --save --variable APP_ID="123456789" --variable APP_NAME="myApplication" --variable FACEBOOK_HYBRID_APP_EVENTS="true"
Please check this repo for an example app using this feature.
NOTE(iOS): This feature only works with WKWebView so if using an old version of Cordova, an additional plugin (e.g cordova-plugin-wkwebview-engine) is needed.
This Plugin supports Facebook's GDPR Compliance Delaying Automatic Event Collection.
In order to enable this feature in your Cordova app, please set the FACEBOOK_AUTO_LOG_APP_EVENTS variable to "false" (default is true).
$ cordova plugin add cordova-plugin-facebook-connect --save --variable APP_ID="123456789" --variable APP_NAME="myApplication" --variable FACEBOOK_AUTO_LOG_APP_EVENTS="false"
Then, re-enable auto-logging after an end User provides consent by calling the setAutoLogAppEventsEnabled
method and set it to true.
facebookConnectPlugin.setAutoLogAppEventsEnabled(true, function() {
console.log('setAutoLogAppEventsEnabled success');
}, function() {
console.error('setAutoLogAppEventsEnabled failure');
});
To disable collection of advertiser-id
, please set the FACEBOOK_ADVERTISER_ID_COLLECTION variable to "false" (default is true).
$ cordova plugin add cordova-plugin-facebook-connect --save --variable APP_ID="123456789" --variable APP_NAME="myApplication" --variable FACEBOOK_ADVERTISER_ID_COLLECTION="false"
Then, re-enable collection by calling the setAdvertiserIDCollectionEnabled
method and set it to true.
facebookConnectPlugin.setAdvertiserIDCollectionEnabled(true, function() {
console.log('setAdvertiserIDCollectionEnabled success');
}, function() {
console.error('setAdvertiserIDCollectionEnabled failure');
});
To enable advertiser tracking, call the setAdvertiserTrackingEnabled
method.
facebookConnectPlugin.setAdvertiserTrackingEnabled(true, function() {
console.log('setAdvertiserTrackingEnabled success');
}, function() {
console.error('setAdvertiserTrackingEnabled failure');
});
See the Facebook Developer documentation for more details.
When using the same Facebook app with multiple iOS apps, use the FACEBOOK_URL_SCHEME_SUFFIX variable to set a unique URL Suffix for each app. This ensures that Facebook redirects back to the correct app after closing the login window.
$ cordova plugin add cordova-plugin-facebook-connect --save --variable APP_ID="123456789" --variable APP_NAME="myApplication" --variable FACEBOOK_URL_SCHEME_SUFFIX="mysecondapp"
FAQs
Cordova Facebook SDK Plugin
The npm package cordova-plugin-facebook-connect receives a total of 1,601 weekly downloads. As such, cordova-plugin-facebook-connect popularity was classified as popular.
We found that cordova-plugin-facebook-connect demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.