Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

From facebook connect to open graph

Hi everyone,
I'm starting to develop a mobile application using Facebook as authentication. I've seen that Facebook Connect will no more exist, replaced by open graph:
[http://mashable.com/2010/04/21/facebook-kills-facebook-connect/]. I've also seen that the Facebook module from Titanium API use the Facebook Connect protocol.

So I'd like to code my application with open graph protocol and I'm wondering if it's possible to implement it in Titanium application. Or will the Titanium.Facebook change with a next API?

— asked April 29th 2010 by Brice Torriani
  • facebook
  • iphone
  • mobile
0 Comments

4 Answers

  • for those who are trying to use this, please note that now you can access the token directly from the Ti.Facebook API. Once logged in just use Titanium.Facebook.accessToken.

    Example:

    function updateLoginStatus() {
        if(Titanium.Facebook.loggedIn){
            Ti.API.info("Token:"+Titanium.Facebook.accessToken)
        }
    }
    
    — answered August 5th 2011 by Andres Arguello Pitt
    permalink
    0 Comments
  • Ok people if someone is interested, here's the solution I've choosen:
    I used the Titanium.Facebook api to connect with Facebook and get a session (thanks a lot to Altaf Sayani who indicate me how to build a valid session proxy).
    Here is the post about it.

    Then I exchanged the session with an oauth access token
    (see the FB developer page)

    And now I can make the open graph requests!

    Code strong people

    — answered June 7th 2010 by Brice Torriani
    permalink
    1 Comment
    • is a proxy absolutely required? anyone have any code that doesnt use one?

      — commented December 18th 2010 by Anthony Webb
  • @Brice,

    How are you managing the difference between the session expiration from the Titanium.Facebook and the Open Graph one?

    Thanks

    — answered December 30th 2010 by Raul Riera
    permalink
    0 Comments
  • After logging in using the current Ti.Facebook functions to get the session_key, I then use this to exchange it for an access_token to use with the Graph API

    var app_id = 'YOUR_FACEBOOK_APP_ID';
    var app_secret = 'YOUR_FACEBOOK_APP_SECRET';
    
    function exchangeFacebookSessionKeyForAccessToken(){
    
        // Exchanges the current session_key via OAuth for an access_token
    
        var xhr = Titanium.Network.createHTTPClient();
        xhr.timeout = 1000000;
        xhr.onerror = function(e){
            Ti.API.info('IN ERROR ' + e.error);
        };
        xhr.onload = function(){    
    
            var reply = eval('('+this.responseText+')');
            Ti.API.info('Access Token : '+reply[0].access_token);
    
        };
        var endPoint = 'https://graph.facebook.com/oauth/exchange_sessions';
        xhr.open('POST',endPoint);
        xhr.send({
            client_id:app_id,
            client_secret:app_secret,
            sessions:Ti.Facebook.session.session_key
        });
    
    }
    
    — answered December 30th 2010 by Kosso
    permalink
    1 Comment
    • @kosso after loggin in via

      Ti.Facebook.authorize()
      

      I tried you described above and it failed.

      Ti.API.debug( Ti.Facebook.session.session_key);
      

      this returns nothing and the application gets crashed/ hang

      — commented August 3rd 2012 by Sahil Grover
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.