Add-on Facebook module.
The Facebook module is used for connecting your application with Facebook. This module supports the following features:
Logging in to Facebook and authorizing your application with either the Login button or programatically.
Making requests through the Facebook Graph API using the requestWithGraphPath() method.
Sharing content using Facebook dialogs or the Like button.
Using Ti.Facebook with iOS 10 and Xcode 8
The paragraph about custom capabilities was only necessary between Titanium SDK 5.5.0 and 6.0.0. Since 6.0.1.GA, we add the required capabilities automatically, so you don't need to curate your own entitlements file anymore, which will avoid possible issues with concurring values. Please ensure to use both SDK and CLI 6.0.1 (or later).
Note: As of April 30th, 2015, Facebook no longer supports version 1.0 of their API, which includes the FQL and REST APIs. Only the Graph APIs will be supported.
Migration from the Facebook module v4.x to v5.x
dialog() method -- presentWebShareDialog() is deprecated and removed. The module will auto determine if you have a native Facebook App installed. canPresentShareDialog() is also deprecated and removed. For more details, see 'Share Dialogs' and 'Request Dialogs' below.
presentShareDialog() method -- 'name' parameter is deprecated and replaced with 'title'. 'caption' parameter is deprecated and removed.
presentSendRequestDialog() method -- 'to' parameter is deprecated and replaced with 'recipients'. There are a few new parameters as well, for more details, see presentSendRequestDialog()
The following APIs were removed due to changes in the native Facebook SDKs and removal of the Facebook v1.0 REST APIs:
tiapp.xml
file.
For more details, see 'Getting Started' below for more details.
Migration from the Facebook module v3.x to v4.xThe following APIs were removed due to changes in the native Facebook SDKs and removal of the Facebook v1.0 REST APIs:
appid property -- The Facebook application ID can no longer be set programmatically
in the application. Set the Facebook application ID in the tiapp.xml
file.
For more details, see 'Getting Started' below for more details.
dialog() method -- Use either presentSendRequestDialog(), presentInviteDialog(), presentMessengerDialog(), presentShareDialog() or presentWebShareDialog(). For more details, see 'Share Dialogs' and 'Request Dialogs' below.
forceDialogAuth property -- On Android, you can force dialog authorization with the LoginButton.sessionLoginBehavior property.
publishInstall() method -- The underlying Facebook API has been deprecated and is now handled automatically by the module.
request() method -- Due to the removal of the Facebook v1.0 APIs,
all applications should call the Graph APIs instead. If you make any REST API calls
with the request()
method, transition to the Graph APIs and use the
requestWithGraphPath() method.
reauthorize() method -- To request additional Facebook permissions once the user authorizes the application, use either the requestNewReadPermissions() or requestNewPublishPermissions(). For more details, see "Manage Read and Write Permissions" below.
LoginButton style property -- Facebook redesigned its Login button and the style can no longer be changed.
Places API -- Fetch nearby places using the current location or a specified search-tearm.
To use the Facebook module, you need a Facebook application. To create a Facebook App, go to the Facebook Developer App: developers.facebook.com/apps.
Edit the modules
section of your tiapp.xml file to include this module:
<modules>
<!-- Add the appropriate line(s) to your modules section -->
<module platform="android">facebook</module>
<module platform="iphone">facebook</module>
</modules>
Instantiate the module with the require('facebook')
method, then make subsequent API calls
with the new Facebook object.
var fb = require('facebook');
fb.permissions = [FACEBOOK_APP_PERMISSIONS]; // e.g. ['email']
fb.initialize();
fb.authorize();
For the iOS platform, in the ios plist dict
section of your tiapp.xml
file, add the following keys:
FacebookAppID
key with your Facebook App ID as the string valueFacebookDisplayName
key with your Facebook App name (the one from developer.facebook.com
) as the string valueCFBundleURLTypes
key with a single-element array containing a dict as the value, where the dict contains:
CFBundleURLName
key with the application app ID (same value as the id
in the tiapp.xml
file) as the string valueCFBundleURLSchemes
key with a single-element array containing the Facebook App ID prefixed with fb
as a string valueFor example:
<ti:app>
<ios>
<plist>
<dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<!-- Application ID same as the id value in the tiapp.xml file -->
<string>APP_ID</string>
<key>CFBundleURLSchemes</key>
<array>
<!-- Prefix the Facebook App ID with 'fb' -->
<string>fbFACEBOOK_APP_ID</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<!-- Facebook App ID -->
<string>FACEBOOK_APP_ID</string>
<key>FacebookDisplayName</key>
<!-- Facebook App Name from developer.facebook.com -->
<string>FACEBOOK_APP_NAME</string>
</dict>
</plist>
</ios>
</ti:app>
To enable the use of Facebook dialogs (e.g., Login, Share), you also need to include the following key and values in tiapp.xml
to handle the switching in and out of your app:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
If you are using the older Ti.Facebook Module 4.0.5 and wish to support iOS9, you will instead need to include the following key
and values in tiapp.xml
to handle the switching in and out of your app:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fbapi20130214</string>
<string>fbapi20130410</string>
<string>fbapi20130702</string>
<string>fbapi20131010</string>
<string>fbapi20131219</string>
<string>fbapi20140410</string>
<string>fbapi20140116</string>
<string>fbapi20150313</string>
<string>fbapi20150629</string>
<string>fbauth</string>
<string>fbauth2</string>
<string>fb-messenger-api20140430</string>
</array>
For iOS9 and titanium 5.0.0.GA and above, App Transport Security is disabled by default.
If you choose to enable it, you have to set the following keys and values in tiapp.xml
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>facebook.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<key>fbcdn.net</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
<key>akamaihd.net</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
</dict>
</dict>
Since Facebook module v4.0.0, for the Android platform, you need to:
string.xml
fileModify the Android Manifest
Add the Facebook Login activity to the android manifest
section of your tiapp.xml
file.
You may need to add the manifest
and application
elements.
<ti:app>
<android xmlns:android="http://schemas.android.com/apk/res/android">
<manifest>
<application>
<activity android:name="com.facebook.FacebookActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:label="YourAppName"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" />
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
</application>
</manifest>
</android>
<ti:app>
Add the Facebook App ID to Android Resources
Add a string element to the /platform/android/res/values/strings.xml
file with the name
attribute set to facebook_app_id
and the node text set to your Facebook App ID. Create the
file if it does not exist.
<resources>
<string name="facebook_app_id">FACEBOOK_APP_ID</string>
</resources>
Create a Facebook Proxy
Use the createActivityWorker() method to create a
Facebook proxy. Pass the method a dictionary with the lifecycleContainer
property set to
the current active instance of a standalone Window (window not contained in a tab group) or TabGroup.
Create the proxy before calling the open()
method on either the window or tab group.
The Facebook module needs to hook into the lifecycle events of the current active activity in order to synchronize its state between various activities in the application, for example, to update the label of the Login button when the user logs in or out of Facebook.
Attach the proxy to the Window or TabGroup object, so it does not get garbage collected.
win.fbProxy = fb.createActivityWorker({lifecycleContainer: win});
To use Facebook, a user must logged into Facebook and explicitly authorize the application to perform certain actions, such as accessing profile information or posting status messages.
There are two ways to initiate the login process:
Call authorize to prompt the user to login and authorize the application. Before calling this method, set the permissions property if additional permissions are needed.
Create a Facebook LoginButton to allow the user to
log in if desired. You can add either read permissions or write permissions,
otherwise the default is to request for the public_profile
permission.
Note that Facebook does not support setting both readPermissions
and publishPermissions
properties at the same time when using the LoginButton.
Which approach you take depends on your UI and how central Facebook is to your application.
In order to read or write content to a user's Facebook page, you need to request permission from the user. You can either request permissions when the user authorizes your application or request permissions on the fly.
Before the user logs in and authorizes the application, you can request permissions for the application to use by either:
authorize()
method to
have the user login and authorize the application.For a complete list of permissions, see the official Facebook Permissions Reference
Refresh Application Permissions
Since the user can selectively turn application permissions on and off from their Facebook page, the application may need to refresh its granted permissions.
To refresh the application's permissions, call the refreshPermissionsFromServer() method, then listen for the tokenUpdated event to be notified when permissions are updated.
fb.addEventListener('tokenUpdated', function(e) {
Ti.API.info('Updated permissions: ' + JSON.stringify(fb.permissions));
});
fb.refreshPermissionsFromServer();
Request Additional Read Permissions
To request additional read permissions once the user authorizes your application, use the requestNewReadPermissions() method.
Check the permissions property to make sure the user accepted the request for additional permissions.
var fb = require('facebook');
fb.requestNewReadPermissions(['read_stream','user_hometown', etc...], function(e) {
if (e.success) {
fb.requestWithGraphPath(...);
} else if (e.cancelled) {
....
} else {
Ti.API.debug('Failed authorization due to: ' + e.error);
}
});
Request Additional Write Permissions
To request additional write permissions once the user authorizes your application, use the
requestNewPublishPermissions() method.
Note that in addition to passing the permissions to request, you need to also pass an AUDIENCE_*
constant to indicate the default audience when positing content.
Check the permissions property to make sure the user accepted the request for additional permissions.
var fb = require('facebook');
fb.requestNewPublishPermissions(['read_stream','user_hometown', etc...], fb.AUDIENCE_FRIENDS, function(e) {
if (e.success) {
fb.requestWithGraphPath(...);
} else if (e.cancelled) {
....
} else {
Ti.API.debug('Failed authorization due to: ' + e.error);
}
});
The Share dialog prompts a person to publish an individual story or an Open Graph story to their timeline. This does not require the user to authorize your app or any extended permissions, so it is the easiest way to enable sharing.
The Share dialog uses the Facebook apps interface, so the Facebook app needs to be installed. If the Facebook app is not installed, the application can use the Feed dialog that presents the dialog in a web-based view as a back up if the Share dialog is not available.
To present a Share dialog to a user, use the canPresentShareDialog property to check if the application can use the Share dialog. If the application supports the Share dialog, call the presentShareDialog() to present it, else call the presentWebShareDialog() method to present the Feed dialog.
Pass either method parameters you want to add to the post, such as a link
or hashtag
, or to
share the user's status, do not pass any parameters to the methods.
To monitor if the share request succeeded or not, listen to the shareCompleted
event. It uses the same arguments as presentMessengerDialog
.
fb.addEventListener('shareCompleted', function (e) {
if (e.success) {
Ti.API.info('Share request succeeded.');
} else {
Ti.API.warn('Failed to share.');
}
});
fb.presentShareDialog({
link: 'https://appcelerator.com/',
hashtag: 'codestrong'
});
For details on the Share dialog, see the official Facebook Share Dialogs documentation.
A request dialog allows a user to invite another user to use your application. Facebook will send a private message to the recipient. The typical use case is to invite another user to play a game. If you want to invite people to your application which is not a game, use the presentInviteDialog() method instead.
To send a request to a user, call the
presentSendRequestDialog() method and pass the
method a dictionary with the message
property set the message you want to send the invited user.
Optional: You can set the title
property with a title string. You can also set the data
property
with a dictionary of custom parameters. If you want to preselect users to send invite to, you can set
the to
property with string of values that are facebook ids seperated by comma.
To monitor if the request succeeded or not, listen to the requestDialogCompleted event.
fb.addEventListener('requestDialogCompleted', function (e) {
if (e.success) {
Ti.API.info('request succeeded.');
} else {
Ti.API.warn('Failed to share.');
}
});
fb.presentSendRequestDialog({
message: 'Go to https://appcelerator.com/',
title: 'Invitation to Appcelerator',
recipients: ['123456789', '123456788'],
data: {
badge_of_awesomeness: '1',
social_karma: '5'
}
});
For details on request dialogs see the official Facebook Request Dialogs documentation.
A messenger dialog allows a user to send content to the Facebook Messenger using your application.
To send a message to a user, call the presentMessengerDialog() method
and pass the method a dictionary with the optional values "hashtag", "link", "to", "placeID"
and "referal". It uses the same arguments as presentShareDialog
.
fb.presentMessengerDialog({
link: "https://appcelerator.com", // The link you want to share
referal: "ti_app", // The referal to be added as a suffix to your link
placeID: "my_id", // The ID for a place to tag with this content
to: [] // List of IDs for taggable people to tag with this content
});
For details on dialog see the official Facebook Messenger Dialogs documentation.
The Messenger button provides a quick mechanism for users to share content to the Facebook Messenger. A click on the button can share the content to multiple users.
To create a Messenger button, call the createMessengerButton() method and pass the "mode" and "style" properties:
var messengerButton = fb.createMessengerButton({
mode: fb.MESSENGER_BUTTON_MODE_RECTANGULAR
style: fb.MESSENGER_BUTTON_STYLE_BLUE
});
win.add(messengerButton);
For more information, see the MessengerButton API reference.
The Like button provides a quick mechanism for users to share content. A click on the button will share the content on the user's Facebook page.
To create a Like button, call the createLikeButton() method
and pass it a dictionary with the objectID
assigned to either a URL or Open Graph object ID
you want to share. Add the button instance to a view to display it.
var likeButton = fb.createLikeButton({
objectID: "https://www.facebook.com/appcelerator"
});
win.add(likeButton);
For more information, see the LikeButton API reference.
The Facebook SDK supports fetching places since Graph API v2.9. You are able to use the official FBSDKPlacesKit API in Titanium SDK 6.2.0 and later to fetch places by the current user location or a specified search tearm. Example of using the current location:
fb.fetchNearbyPlacesForCurrentLocation({
confidenceLevel: fb.PLACE_LOCATION_CONFIDENCE_NOT_APPLICABLE, // optional
fields: [], // optional, see https://developers.facebook.com/docs/places/fields
success: function(e) {
alert('Successfully fetched places!');
Ti.API.info(e);
},
error: function(e) {
alert('Error fetching places!');
Ti.API.error(e);
}
});
Check out the full example in examples/facebook_places.js.
Displays the Facebook Login and Like buttons in a window.
app/alloy.js
:
// Make API calls to Alloy.Globals.Facebook
Alloy.Globals.Facebook = require('facebook');
app/views/index.xml
:
<Alloy>
<Window backgroundColor="white">
<LoginButton id="fbLogin" module="facebook" top="25" />
<LikeButton id="fbLike" module="facebook" top="100" />
</Window>
</Alloy>
app/controllers/index.js
:
$.fbLike.objectID = "http://www.facebook.com/appcelerator";
if (OS_ANDROID) {
$.index.fbProxy = Alloy.Globals.Facebook.createActivityWorker({lifecycleContainer: $.index});
}
$.index.open();
Shows official Facebook dialog for logging in the user and prompting the user to approve your requested permissions. Listen for the module's login event to determine whether the request succeeded.
var fb = require('facebook');
fb.initialize();
fb.addEventListener('login', function(e) {
if (e.success) {
alert('login from uid: '+e.uid+', name: '+ JSON.parse(e.data).name);
label.text = 'Logged In = ' + fb.loggedIn;
}
else if (e.cancelled) {
// user cancelled
alert('cancelled');
}
else {
alert(e.error);
}
});
fb.authorize();
Logout the user and forget the authorization token. The logout event is fired after the user is logged out.
fb.addEventListener('logout', function(e) {
alert('Logged out');
});
fb.logout();
You can use the the native Facebook LoginButton to allow the user to log in as required. The button updates its state automatically depending on whether the user is logged in or not. When the user is logged in, then the button will show "Logout", and vice-versa.
Note that you don't need to set a click listener or anything else on the button. To be notified when the user logs in or out, add event listeners for the login and logout events provided by the Facebook module, as in the example below.
// Don't forget to set your requested permissions, else the login button won't be effective.
var win = Ti.UI.createWindow({backgroundColor: 'white'});
var fb = require('facebook');
fb.addEventListener('login', function(e) {
if (e.success) {
alert('Logged in');
}
});
fb.addEventListener('logout', function(e) {
alert('Logged out');
});
if (Ti.Platform.name === 'android') {
win.fbProxy = fb.createActivityWorker({lifecycleContainer: win});
}
// Add the button. Note that it doesn't need a click event listener.
win.add(fb.createLoginButton({
readPermissions: ['read_stream','email'],
top: 50
}));
win.open()
This example makes a call to the "me" graph path, which represents the current user. The JSON results are simply displayed in an alert. This example assumes the user is already logged in. You can check this with loggedIn.
fb.requestWithGraphPath('me', {}, 'GET', function(e) {
if (e.success) {
alert(e.result);
} else if (e.error) {
alert(e.error);
} else {
alert('Unknown response');
}
});
This example posts a photo to the user's account using the Graph API. This requires the "publish_actions" permission.
var B1_TITLE = 'Upload Photo from Gallery with Graph API';
var b1 = Ti.UI.createButton({
title:B1_TITLE,
left: 10, right: 10, top: 0, height: 80
});
b1.addEventListener('click', function() {
Titanium.Media.openPhotoGallery({
success:function(event)
{
b1.title = 'Uploading Photo...';
var data = {picture: event.media};
// If publish_actions permission is not granted, request it
if (fb.permissions.indexOf('publish_actions') < 0) {
fb.requestNewPublishPermissions(['publish_actions'], fb.AUDIENCE_FRIENDS, function(e) {
if (e.success) {
Ti.API.info('Permissions:'+fb.permissions);
fb.requestWithGraphPath('me/photos', data, "POST", showRequestResult);
}
if (e.error) {
Ti.API.info('Publish permission error');
}
if (e.cancelled) {
Ti.API.info('Publish permission cancelled');
}
});
} else {
fb.requestWithGraphPath('me/photos', data, "POST", showRequestResult);
}
},
cancel:function()
{
},
error:function(error)
{
},
allowEditing:true
});
});
For more information on posting photos, see:
This example posts a photo to the user's account using the Graph API. This requires the "publish_actions" permission.
var b2 = Ti.UI.createButton({
title: 'Upload Photo from file with Graph API',
left: 10,
right: 10,
top: 90,
height: 80
});
b2.addEventListener('click', function() {
b2.title = 'Uploading Photo...';
var f = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'images', 'flower.jpg');
var blob = f.read();
var data = {
caption: 'behold, a flower',
picture: blob
};
// If publish_actions permission is not granted, request it
if (fb.permissions.indexOf('publish_actions') < 0) {
fb.requestNewPublishPermissions(['publish_actions'], fb.AUDIENCE_FRIENDS, function(e) {
if (e.success) {
Ti.API.info('Permissions:'+fb.permissions);
fb.requestWithGraphPath('me/photos', data, "POST", showRequestResult);
}
if (e.error) {
Ti.API.info('Publish permission error');
}
if (e.cancelled) {
Ti.API.info('Publish permission cancelled');
}
});
} else {
fb.requestWithGraphPath('me/photos', data, "POST", showRequestResult);
}
});
For more information on posting photos, see:
This example shows how to use the Share Dialog.
var wallDialog = Ti.UI.createButton({
title: 'Share URL with Share Dialog',
top: 135,
left: 10,
right: 10,
height: 40
});
wallDialog.addEventListener('click', function() {
if (fb.getCanPresentShareDialog()) {
fb.presentShareDialog({
link: 'https://appcelerator.com/',
name: 'great product',
description: 'Titanium is a great product',
caption: 'it rocks too',
picture: 'http://www.appcelerator.com/wp-content/uploads/scale_triangle1.png'
});
} else {
fb.presentWebShareDialog({
link: 'https://appcelerator.com/',
name: 'great product',
description: 'Titanium is a great product',
caption: 'it rocks too',
picture: 'http://www.appcelerator.com/wp-content/uploads/scale_triangle1.png'
});
}
});
For more information on Facebook Dialogs, see:
This example shows how to use the Invite Dialog.
var wallDialog = Ti.UI.createButton({
title: 'Invite friends!',
top: 135,
left: 10,
right: 10,
height: 40
});
wallDialog.addEventListener('click', function() {
FB.presentInviteDialog({
appLink: "https://fb.me/xxxxxxxx",
appPreviewImageLink: "https://www.mydomain.com/my_invite_image.jpg"
});
});
For more information on Invite Dialogs, see: Facebook Invite Dialog Reference
This example shows how to share images, GIF's and videos to the Facebook messenger.
var btn = Ti.UI.createButton({
title: "Share media to messenger"
});
btn.addEventListener("click", function(e) {
var media = [
Ti.UI.createView({height: 30,width:30,backgroundColor: "#ff0"}).toImage(), // Image blob
Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "test.gif").read(), // GIF Blob
Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "movie.mp4").read() // Video Blob
];
var options = Ti.UI.createOptionDialog({
options: ["Photo", "GIF", "Video", "Cancel"],
cancel: 3
});
options.addEventListener("click", function(e) {
if (e.index == 3) {
return;
}
FB.shareMediaToMessenger({
media: media[e.index],
metadata: "Ti rocks!",
link: "https://appcelerator.com",
//renderAsSticker: true // Only for photos e.g. selfies
});
});
options.show();
});
For more information on sharing media to the Facebook Messenger, see:
This example shows how to use the requestNewPublishPermissions
method to request additional permissions
to publish a post to the user's wall.
fb.requestNewPublishPermissions(['publish_actions'], fb.AUDIENCE_FRIENDS, function(e) {
if (e.success) {
fb.requestWithGraphPath('me/feed', null, "POST", showRequestResult);
} else {
Ti.API.debug('Failed authorization due to: ' + e.error);
}
});
The user is asking for an object from friends.
The user is asking for an object from friends.
Use to set the actionType with presentSendRequestDialog()
The user is sending an object to the friends.
The user is sending an object to the friends.
Use to set the actionType with presentSendRequestDialog()
It is the turn of the friends to play against the user in a match.
It is the turn of the friends to play against the user in a match.
Use to set the actionType with presentSendRequestDialog()
Published content is visible to all Facebook users.
Published content is visible to all Facebook users.
Use to set the default audience with either LoginButton.audience or requestNewPublishPermissions.
Published content is only visible to the user and user's friends.
Published content is only visible to the user and user's friends.
Use to set the default audience with either LoginButton.audience or requestNewPublishPermissions.
Published content is only visible to the user.
Published content is only visible to the user.
Use to set the default audience with either LoginButton.audience or requestNewPublishPermissions.
Use with LoginButton.style to specify the default login button reading "Connect" or "Login".
Use with LoginButton.style to specify the default login button reading "Connect" or "Login".
This property has been removed since 4.0.0
Use with LoginButton.style to specify a wide login button reading "Connect with Facebook" or "Login with Facebook".
Use with LoginButton.style to specify a wide login button reading "Connect with Facebook" or "Login with Facebook".
This property has been removed since 4.0.0
Friends not using the app can be displayed.
Friends not using the app can be displayed.
Use to set the filter with presentSendRequestDialog()
Friends using the app can be displayed.
Friends using the app can be displayed.
Use to set the filter with presentSendRequestDialog()
No filter all friends can be displayed.
No filter all friends can be displayed.
Use to set the filter with presentSendRequestDialog()
Opens login window in the default Web Browser (Safari/Firefox etc...)
Opens login window in the default Web Browser (Safari/Firefox etc...)
Expose Facebook Login for devices such as Android TV and Fire TV.
Expose Facebook Login for devices such as Android TV and Fire TV.
Opens login window with the native Facebook app. On iOS it will attempt to
fallback to
Note: As of today (Facebook SDK 4.11.0), Facebook seems to not allow logging in using the Facebook app to login, so this constant won't work proper on iOS. This issue is discussed here.
Opens login window with the native Facebook app. On Android it will attempt to
fallback to
Attempts to login with through the Facebook account currently signed in through Settings.
Attempts to login with through the Facebook account currently signed in through Settings.
Opens login window through a modal browser window.
Opens login window through a modal browser window.
The default behavior. The tooltip will only be displayed if the app is eligible (determined by possible server round trip).
Force disable. In this case you can still exert more refined control by manually constructing a new login button.
Force display of the tooltip (typically for UI testing).
Force display of the tooltip (typically for UI testing).
Light blue background, white text, faded blue close button.
Light blue background, white text, faded blue close button.
Dark gray background, white text, light gray close button.
Dark gray background, white text, light gray close button.
Use with MessengerButton.mode to specify the default send button reading "Send".
Use with MessengerButton.mode to specify the default send button reading "Send".
You can localize the button by localizing "Send" in your strings.xml. Learn more about that topic here.
Use with MessengerButton.mode to specify the default send button reading "Send".
Use with MessengerButton.mode to specify the default send button reading "Send".
You can localize the button by localizing "Send" in your strings.xml. Learn more about that topic here.
Use with MessengerButton.style to specify the default send button style.
Use with MessengerButton.style to specify the default send button style.
Use with MessengerButton.style to specify the default send button style.
Use with MessengerButton.style to specify the default send button style.
Use with MessengerButton.style to specify the default send button style.
Use with MessengerButton.style to specify the default send button style.
High confidence level.
High confidence level.
Low confidence level.
Low confidence level.
Medium confidence level.
Medium confidence level.
Used to indicate that any level is acceptable as a minimum threshold.
Used to indicate that any level is acceptable as a minimum threshold.
Acts with the most appropriate mode that is available.
Acts with the most appropriate mode that is available.
Use with presentShareDialog().
Displays the feed dialog in a webview within the app.
Displays the feed dialog in a webview within the app.
Use with presentShareDialog().
Displays the dialog in the iOS integrated share sheet.
Attempt single sign-on, then fallback to dialog authorization.
Attempt single sign-on, then fallback to dialog authorization.
Use with the LoginButton.sessionLoginBehavior property.
Do not attempt single sign-on and only use dialog authorization.
Do not attempt single sign-on and only use dialog authorization.
Use with the LoginButton.sessionLoginBehavior property.
OAuth token set after a successful authorize
.
OAuth token set after a successful authorize
.
The name of the API that this proxy corresponds to.
The name of the API that this proxy corresponds to.
The value of this property is the fully qualified name of the API. For example, Button
returns Ti.UI.Button
.
If not explicitly set, the default will be read from the application's plist (FacebookAppID) which is the recommended way.
Since Titanium SDK 6.2.0, this property also has a getter to return the currently set appID.
Indicates if the proxy will bubble an event to its parent.
Some proxies (most commonly views) have a relationship to other proxies, often established by the add() method. For example, for a button added to a window, a click event on the button would bubble up to the window. Other common parents are table sections to their rows, table views to their sections, and scrollable views to their views. Set this property to false to disable the bubbling to the proxy's parent.
Default: true
Checks if the device can support the use of the Facebook Open Graph action dialog from the Facebook App.
Checks if the device can support the use of the Facebook Open Graph action dialog from the Facebook App.
Time at which the accessToken
expires.
Time at which the accessToken
expires.
Indicates whether the login should use the traditional dialog-based authentication.
This property has been removed since 4.0.0
Set to false
to enable Single-Sign-On (SSO) in cases where the official Facebook app is on the
device. Default is true
, meaning the traditional, dialog-based
authentication is used rather than SSO. See the
Facebook Mobile Guide for
details of their Single-Sign-On scheme.
To use the built-in iOS 6 login, set this property to false
.
This property is read-only on Mobile Web.
Default: true
The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.
The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.
If this property is set to a Window or TabGroup, then the corresponding Activity lifecycle event callbacks will also be called on the proxy. Proxies that require the activity lifecycle will need this property set to the appropriate containing Window or TabGroup.
Defines the behavior that the module will attempt to use for authorize().
Be sure to set this before calling authorize if this is needed. It is recommended to follow Facebook's guidelines for ideal login behavior
This API can be assigned the following constants:
Default: Defaults to
Array of permissions to request for your app.
Array of permissions to request for your app.
Be sure the permissions you want are set before calling authorize.
For a complete list of permissions, see the official Facebook Permissions Reference
On iOS, do not request any write permissions before calling the authorize()
method. Use the
requestNewPublishPermissions()
to request write permissions once the user authorizes the application.
Prior to Release 4.0.0
To use the build-in iOS 6 login, this property cannot contain any of the following: offline_access, publish_actions, publish_stream, publish_checkins, ads_management, create_event, rsvp_event, manage_friendlists, manage_notifications, or manage_pages.
Adds the specified callback as an event listener for the named event.
Name of the event.
Callback function to invoke when the event is fired.
Applies the properties to the proxy.
Properties are supplied as a dictionary. Each key-value pair in the object is applied to the proxy such that myproxy[key] = value.
A dictionary of properties to apply.
Creates a Facebook proxy to hook into the activity of either a standalone Titanium.UI.Window (not inside a TabGroup) or Titanium.UI.TabGroup.
Set the lifecycleContainer
property in the dictionary passed to the method to either
the current active instance of a Titanium.UI.Window or Titanium.UI.TabGroup in order to monitor the activity's
lifecycle events, required by Facebook to synchronize its state between various
activities in the application.
The proxy object must be created before calling the open()
method on the associated Window
or TabGroup.
Properties to set on a new object, including any defined by Titanium.Proxy except those marked not-creation or read-only.
Note: You must set the lifecycleContainer
property.
Creates and returns an instance of Modules.Facebook.LikeButton.
Properties to set on a new object, including any defined by Modules.Facebook.LikeButton except those marked not-creation or read-only.
Creates and returns an instance of Modules.Facebook.LoginButton.
Properties to set on a new object, including any defined by Modules.Facebook.LoginButton except those marked not-creation or read-only.
Creates and returns an instance of Modules.Facebook.MessengerButton.
Properties to set on a new object, including any defined by Modules.Facebook.MessengerButton except those marked not-creation or read-only.
Fetch the deferred app link
Deferred deep linking allows you to send people to a custom view after they installed your app via the app store.
Callback to invoke when the request completes.
Query for places the device is likely located in.
This is an asynchronous call, due to the need to fetch the current location from the device. Note that the results of the graph request are improved if the user has both Wi-Fi and Bluetooth enabled.
Note: Remember to request the location permssions with Titanium.Geolocation
and include either the NSLocationWhenInUseUsageDescription
or the
NSLocationAlwaysUsageDescription
key in your plist before using this method.
The Facebook graph also requires the FacebookClientToken
to be present in the
plist, so check the Facebook Developer Portal > Apps > Your App > Settings > Advanced
for your OAuth client-token.
The Minimum Confidence level place estimate candidates must meet.
This API can be assigned the following constants:
A list of fields that you might want the request to return. See the Facebook docs for all possible values.
The callback triggered when places are successfully fetched.
The callback triggered when places could not be fetched.
Query for nearby places using the device's current location and search-term.
This is an asynchronous call, due to the need to fetch the current location from the device.
Note: Remember to request the location permssions with Titanium.Geolocation
and include either the NSLocationWhenInUseUsageDescription
or the
NSLocationAlwaysUsageDescription
key in your plist before using this method.
The Facebook graph also requires the FacebookClientToken
to be present in the
plist, so check the Facebook Developer Portal > Apps > Your App > Settings > Advanced
for your OAuth client-token.
The term to search for in the Places Graph.
The categories for the place. Each string in this array must be a category recognized by the SDK. See the Facebook Docs for all possible values.
A list of fields that you might want the request to return. See the Facebook docs for all possible values.
The search radius. For an unlimited radius, use 0.
A pagination cursor.
The callback triggered when places are successfully fetched.
The callback triggered when places could not be fetched.
Fires a synthesized event to any registered listeners.
Name of the event.
A dictionary of keys and values to add to the Titanium.Event object sent to the listeners.
Gets the value of the forceDialogAuth property.
This method has been removed since 4.0.0
Loads a cached Facebook session if available, then fires the login
event.
Be sure to set your login and logout
event listeners before calling initialize
.
**Note: This method needs to be called before calling authorize in order to be handle the auth-flow correctly. Otherwise, you might see a white screen without any response.
The timeout
parameter was deprecated in version 5.0.0 of Ti.Facebook and is not used anymore.
Logs a custom event to Facebook.
From the Facebook API Reference:
Events are not sent immediately when logged. They're cached and flushed out to the Facebook servers in a number of situations:
Some things to note when logging events:
_
, -
or spaces.Arbitrary string to log as an event.
An arbitrary number that can represent any value (e.g., a price or a quantity). When reported, all of the valueToSum properties will be summed together in Facebook Analytics for Apps (since 5.4.0).
A dictionary object containing optional parameters (since 5.4.0).
Log a purchase of the specified amount, in the specified currency.
Purchase amount to be logged, as expressed in the specified currency. This value will be rounded to the thousandths place (e.g., 12.34567 becomes 12.346).
Currency, is denoted as, e.g. "USD", "EUR", "GBP". See ISO-4217 for specific values.
Log an app event that tracks that the application was open via Push Notification.
Notification payload received via in the push-notification callback.
Name of the action that was taken.
Clears the OAuth accessToken
and logs out the user.
Opens a supported Facebook Invite dialog from the Facebook App.
To monitor if the share request succeeded or not, listen to the shareCompleted event.
A dictionary object containing required and optional parameters.
Opens a supported Messenger dialog from the Facebook Messenger App.
Be sure to check if the device can support this method by calling canOpenURL with "fb-messenger-api://" before using this method. If true, you can use this method. If false, the Facebook Messenger application is probably not installed in the device.
Listen for the shareCompleted to be notified if the attempt was successful or not.
A dictionary object containing optional parameters.
Opens an App Request dialog.
A requestDialogCompleted
event is generated to indicate if the request attempt was successful or unsuccessful,
and the resultURL.
A dictionary object containing parameters.
Makes a request to Facebook to get the latest permissions granted.
Facebook now grants total control over granted permissions, and if the user modified the permissions outside of your app your cached token may not be updated.
Listen for the tokenUpdated event to be notified if the attempt was successful.
Removes the specified callback as an event listener for the named event.
Multiple listeners can be registered for the same event, so the
callback
parameter is used to determine which listener to remove.
When adding a listener, you must save a reference to the callback function in order to remove the listener later:
var listener = function() { Ti.API.info("Event listener called."); }
window.addEventListener('click', listener);
To remove the listener, pass in a reference to the callback function:
window.removeEventListener('click', listener);
Name of the event.
Callback function to remove. Must be the same function passed to addEventListener
.
Makes a request to Facebook for additional write permissions.
Note that it is not an error for the user to 'Skip' your requested permissions,
so you should check the module's permissions
property following the call.
Array of additional permissions to request. For a complete list of permissions, see the official Facebook Permissions Reference
The extent of the visibility write permissions will have.
This API can be assigned the following constants:
Callback to invoke when the request completes.
Makes a request to Facebook for additional read permissions.
Note that it is not an error for the user to 'Skip' your requested permissions,
so you should check the module's permissions
property following the call.
Array of additional permissions to request. For a complete list of permissions, see the official Facebook Permissions Reference
Callback to invoke when the request completes.
Makes a Facebook Graph API request.
If the request requires user authorization, the user must be logged in, and your app must be authorized to make the request. You can check the loggedIn property to determine if the user is logged in.
Every Facebook object has an associated path. For example, "me" requests information about the current user.
For a complete list of Graph API methods, parameters and return types, see the official Facebook Graph API documentation.
Graph API path to request.
A dictionary object for setting parameters required by the call, if any.
The HTTP method (GET/POST/DELETE) to use for the call.
Callback to invoke when the request completes.
Sets the value of the appID property.
New value for the property.
Sets the value of the bubbleParent property.
New value for the property.
Set a new access token for using Facebook services.
A dictionary object containing required and optional parameters.
Note: There is an open issue in the native Facebook SDK causing the appID from not being updated although specified in the parameters. You can use the appID setter to change the appID inside your app.
Sets the value of the forceDialogAuth property.
This method has been removed since 4.0.0
New value for the property.
Sets the value of the lifecycleContainer property.
New value for the property.
Sets the value of the loginBehavior property.
New value for the property.
Sets the value of the permissions property.
New value for the property.
Sets a device token to register the current application installation for push notifications.
Device-token received when registering for push-notifications.
Fired when the Invite dialog is closed.
Returns true
if request succeeded, false
otherwise.
Indicates if the user canceled the request by closing the dialog.
Error message, if any returned.
Will be undefined if success
is true
.
Source object that fired the event.
Name of the event fired.
True if the event will try to bubble up if possible.
Set to true to stop the event from bubbling.
Fired at session login.
Indicates if the user was logged in successfully.
Returns true
if request succeeded, false
otherwise.
Indicates if the user canceled the login request by closing the dialog.
Error message, if any returned.
Will be undefined if success
is true
.
Error code.
Error code will be 0 if success
is true
, nonzero otherwise. If the error
was generated by the operating system, that system's error value is used.
Otherwise, this value will be -1.
User ID returned by Facebook if the login was successful.
Data returned by Facebook when we query for the UID (using graph path "me") after a successful login. Data is in JSON format, and includes information such as user name, locale and gender.
Source object that fired the event.
Name of the event fired.
True if the event will try to bubble up if possible.
Set to true to stop the event from bubbling.
Fired at session logout.
Source object that fired the event.
Name of the event fired.
True if the event will try to bubble up if possible.
Set to true to stop the event from bubbling.
Fired when the Send Request dialog is closed.
Returns true
if request succeeded, false
otherwise.
Indicates if the user canceled the request by closing the dialog.
Error message, if any returned.
Will be undefined if success
is true
.
data returned by Facebook. See Facebook reference for details.
Source object that fired the event.
Name of the event fired.
True if the event will try to bubble up if possible.
Set to true to stop the event from bubbling.
Fired when refreshPermissionsFromServer is completed.
Source object that fired the event.
Name of the event fired.
True if the event will try to bubble up if possible.
Set to true to stop the event from bubbling.