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?
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) } }
-
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
-
@Brice,
How are you managing the difference between the session expiration from the Titanium.Facebook and the Open Graph one?
Thanks
-
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 }); }