Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-27] API - Facebook Connect Integration

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2011-04-17T01:50:10.000+0000
Affected Version/sn/a
Fix Version/sRelease 0.7.0
ComponentsiOS
Labelsfacebook, ios, iphone
ReporterNolan Wright
AssigneeBlain Hamon
Created2011-04-15T02:22:41.000+0000
Updated2011-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();

Comments

  1. Jeff Haynie 2011-04-15

    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() ?

  2. Marshall Culpepper 2011-04-15

    Facebook connect (and further OAuth) could be a really killer feature for Desktop as well..

  3. Jeff Haynie 2011-04-15

    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.

       var button = Titanium.Facebook.createLoginButton({
           'id':'b',
           'style':'normal',
           'apikey':Titanium.App.Properties.getString("facebook.apikey"),
           'secret':Titanium.App.Properties.getString("facebook.secret")
       });
       button.addEventListener('login',function()
       {
           console.info("LOGIN");
       });
       button.addEventListener('logout',function()
       {
           console.info("LOGOUT");
       });
       

    The style property can either be normal (default if not specified) or wide.

    Query

    You can execute FQL query.

       Titanium.Facebook.query("select uid,name from user where uid == "+Titanium.Facebook.getUserId(),function(r)
       {
           console.info("QUERY RESULT RETURNED success = "+r.success+", error = "+r.error+", data="+r.data);
       });
       

    Explicit Login

    You can cause explicit login

       Titanium.Facebook.login(function(result)
       {
          console.info("login success="+result.success);
       });
       

    Explicit Logout

    You can cause explicit logout

       Titanium.Facebook.logout(function(result)
       {
          console.info("logout success="+result.success);
       });
       

    Login status

    You can determine the login status.

       Titanium.Facebook.isLoggedIn();
       

    Login user id

    You can determine the user id of the logged in user or null if not logged in

       Titanium.Facebook.getUserId();
       

    Request extended permission

    You can request extend permissions

       Titanium.Facebook.requestPermission("publish_feed",function(result)
       {
          console.debug("permission success="+result.success);
       });
       

    Publish to Feed

    You can publish to users feed

       Titanium.Facebook.publishFeed(123456789,{'img':'http://foo/bar.png'},'nolan is cool',function(result)
       {
          console.debug("publish success success="+result.success);
       });
       
  4. Jeff Haynie 2011-04-15

    (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...

  5. Jeff Haynie 2011-04-15

    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.

       Titanium.Facebook.execute("facebook.Users.getStatus",null,function(evt)
       {
          console.info("evt = "+evt+", success="+evt.success+",cancel="+evt.cancel+",error="+evt.error+",json="+Ti._JSON(evt.data));
       });
       
  6. Nolan Wright 2011-04-15

    added in 0.7.0

JSON Source