Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
cordova-plugin-facebook4
Advanced tools
Use Facebook SDK version 4 in Cordova projects
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-facebook4 --save --variable APP_ID="123456789" --variable APP_NAME="myApplication"
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. However, unlike in the browser, the Cordova application will use the native Facebook app to perform Single Sign On for the user. If this is not possible then the sign on will degrade gracefully using the standard dialog based authentication.
facebookConnectPlugin.login(Array strings of permissions, Function success, Function failure)
NOTE : Developers should call facebookConnectPlugin.browserInit(<appId>)
before login - Web App ONLY (see Web App Guide)
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.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",
caption: "Such caption, very feed.",
description: "Much description",
picture: 'http://example.com/image.png'
}
Game request:
{
method: "apprequests",
message: "Come on man, check out my application.",
data: data,
title: title,
actionType: 'askfor',
filters: 'app_non_users'
}
Send Dialog:
{
method: "send",
caption: "Check this out.",
link: "http://example.com",
description: "The site I told you about",
picture: "http://example.com/image.png"
}
Share dialog - Open Graph Story:
{
var obj = {};
obj['og:type'] = 'objectname';
obj['og:title'] = 'Some title';
obj['og:url'] = 'https://en.wikipedia.org/wiki/Main_Page';
obj['og:description'] = 'Some description.';
var ap = {};
ap['expires_in'] = 3600;
var options = {
method: 'share_open_graph', // Required
action: 'actionname', // Required
action_properties: JSON.stringify(ap), // Optional
object: JSON.stringify(obj) // Required
};
}
In case you want to use custom actions/objects, just prepend the app namespace to the name (E.g: obj['og:type'] = 'appnamespace:objectname'
, action: 'appnamespace:actionname'
. The namespace of a Facebook app is found on the Settings page.
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, 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"]
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, Function success, Function failure)
NOTE: Both parameters are required. The currency specification is expected to be an ISO 4217 currency code
activateApp(Function success, Function failure)
facebookConnectPlugin.appInvite(Object options, Function success, Function failure)
Please check out the App Invites Overview before using this. The URL is expected to be an App Link.
Example options:
{
url: "http://example.com",
picture: "http://example.com/image.png"
}
facebookConnectPlugin.appInvite(
{
url: "http://example.com",
picture: "http://example.com/image.png"
},
function(obj){
if(obj) {
if(obj.completionGesture == "cancel") {
// user canceled, bad guy
} else {
// user really invited someone :)
}
} else {
// user just pressed done, bad guy
}
},
function(obj){
// error
console.log(obj);
}
);
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",
picture:'https://www.google.co.jp/logos/doodles/2014/doodle-4-google-2014-japan-winner-5109465267306496.2-hp.png',
name:'Test Post',
message:'First photo post',
caption: 'Testing using phonegap plugin',
description: 'Posting photo using phonegap facebook plugin'
}, function (response) {
console.log(response)
}, function (response) {
console.log(response)
}
);
FAQs
Cordova Facebook SDK 4 Plugin
We found that cordova-plugin-facebook4 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers 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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.