[TIMOB-27] API - Facebook Connect Integration
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2011-04-17T01:50:10.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 0.7.0 |
Components | iOS |
Labels | facebook, ios, iphone |
Reporter | Nolan Wright |
Assignee | Blain Hamon |
Created | 2011-04-15T02:22:41.000+0000 |
Updated | 2011-04-17T01:50:10.000+0000 |
Description
Description
The purpose of this API is to enable developers to use the Facebook Connect Objective-C API via Javascript
Create Session
The first step is to create a Facebook Session
var session = Titanium.Facebook.createSession({
apiKey:'my_api_key',
appSecret:'my_app_secret',
proxyURL:'my proxy url'
});
var isLoggedIn = session.resume();
Returns true if user is already logged in, otherwise it returns false
Button Support
We need to add support for two Facebook iPhone buttons:
Titanium.Facebook.CONNECT_BUTTON
Titanium.Facebook.LOGOUT_BUTTON
These should be supported via the systemButton property of the Titanium.UI.createButton API.
Note: the login button when clicked automatically shows the Login Dialog
Login Dialog
This API creates and displays the Facebook Login Dialog
var dialog = Titanium.Facebook.createLoginDialog({
session:mySessionObject,
});
dialog.show();
Login Event
session.addEventListener('login',function(session)
{
// returns the updated session object after successful login
});
Permissions Dialog
This API creates and displays the Facebook Extended Permission Dialog
var dialog = Titanium.Facebook.createPermissionsDialog({
permission:'permission_string'
success:function()
{
// permission granted - do something cool
},
cancel: function()
{
// permission not granted - too bad
}
});
dialog.show();
Generic Facebook API Requests
This API enables you to call any of the support Facebook Connect APIs
var requestData = {name:'value',name2:'value2'};
var request = Titanium.Facebook.executeAPI({
name:'api_name',
data:requestData,
function(result)
{
// result should be JSON object return from API call
}
});
Feed Dialog
This API allows you to publish a story to a user's feed.
var templateDataObj = {key:'value'};
var dialog = Titanium.Facebook.createFeedDialog({
templateBundleId: 12345,
templateData: templateDataObj,
function(result)
{
// was post successful
}
});
dialog.show();
A few questions:
I don't like the session.resume() method - seems weird. Is this their name? Can we just use session.isLoggedIn()? Or is this the api that causes session to start? Maybe if it is, we could have a session.connect() to cause it to connect and then session.isLoggedIn() would return true/false depending on if you've already done this (or not).
is there an API to see if we already have a permission? i.e. I don't want to show dialog if permission has already been granted... how would you do that?
we need a logout capability -- session.logout() ?
Facebook connect (and further OAuth) could be a really killer feature for Desktop as well..
I ended up implementing the API a little differently.
Create Login/Logout Button
Create a Facebook login/logout button and bind it to a specific ID. You can add and remove listeners from this button once created.
The style property can either be normal (default if not specified) or wide.
Query
You can execute FQL query.
Explicit Login
You can cause explicit login
Explicit Logout
You can cause explicit logout
Login status
You can determine the login status.
Login user id
You can determine the user id of the logged in user or null if not logged in
Request extended permission
You can request extend permissions
Publish to Feed
You can publish to users feed
(from [6ec20bf4ca21c075ece508f4def5f2c4daa7c86d]) [#27 state:open] added initial Facebook Connect module for iphone http://github.com/appcelerator/titanium_mobile/commit/6ec20bf4ca21c075ece508f4def5f2c4daa7c86d"> http://github.com/appcelerator/titanium_mobile/commit/6ec20bf4ca21c...
Execute API call
you can execute a facebook method. the 2nd parameter is optional and is any data (as javascript json object) to pass to the method.
added in 0.7.0