Developers Manual > SDK Integration > Facebook > Facebook API References in JavaScript

Facebook API Reference in JavaScript

version: cocos2d-js v3.x
update: Updated almost 3 years ago

FacebookAgent class

plugin.FacebookAgent is a singleton class that encapsulates all the methods. Before doing anything else, you need to initialize the instance first.

Core Methods

Name Description
getInstance Initialize the SDK, and return the instance of plugin.FacebookAgent. Required before doing anything else.
destroyInstance Destroy the instance of plugin.FacebookAgent.
api Call the Facebook Graph API to find out about the user or act on his/her behalf.
dialog Trigger different forms of Facebook created UI dialogs, such as the Share Dialog for one-to-many sharing on Facebook, or the Message Dialog for sending messages to friends.
canPresentDialog Check whether it can trigger a particular form of Facebook created UI dialog based on the current user's device environment.
appRequest Trigger the Request dialog to send a request to one or more of friends from a game.

Auth and Session Methods

Name Description
login Ask a user to authorize your app, or to grant additional authorizations.
logout Log a user entirely out of Facebook.
isLoggedIn Check whether a user is currently logged in and has authorized your app.
getUserId Get the Facebook user ID of the currently logged in user.
getAccessToken Get the access token granted to your application by current user.

Auxiliary Methods

Name Description
canvas.pay Prompt the user to make a payment using Facebook Payments. Desktop only.
activateApp Report the launch of the app, for integration with Facebook app ads. More details at App Events.
logEvent Report an app event, for integration with Facebook app ads. More details at App Events.
logPurchase Report a purchase event, for integration with Facebook app ads. More details at App Events.

Facebook API availability on different platforms

Methods iOS Android Web
api
dialog - shareLink
dialog - shareOpenGraph
dialog - sharePhoto ×
dialog - messageLink
dialog - messageOpenGraph ×
dialog - messagePhoto ×
dialog - feedDialog
appRequest
login
logout
isLoggedIn
getUserId
getAccessToken
canvas.pay × ×
activateApp
logEvent
logPurchase

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.