Getting the Access Token from a Facebook Open Graph response in Ruby

Posted by Gearóid on Stack Overflow See other posts from Stack Overflow or by Gearóid
Published on 2010-06-08T13:18:00Z Indexed on 2010/06/08 13:22 UTC
Read the original article Hit count: 308

Filed under:
|
|
|

Hi,

I'm trying to implement single sign-on using facebook in my ruby sinatra app. So far, I've been following this tutorial:

http://jaywiggins.com/2010/05/facebook-oauth-with-sinatra/

I am able to send a request for a user to connect to my application but I'm having trouble actually "getting" the access token. The user can connect without trouble and I receive a response with the "code" parameter, which I'm supposed to use to exchange an Access Token - but its here where I get stuck.

So I submit a url with the following parameters:

https://graph.facebook.com/oauth/access_token/{client_id}&{client_secret}&{code}&{redirect_uri}

The words in the curly brackets above are obviously replaced by the values.

I submit this using the following code:

response = open(url)

This doesn't seem to return anything of use in the way of an access token (it has a @base_uri which is the url I submitted above and few other parameters, though nothing useful looking). However, if I take that url I submitted and paste it into a browser, I receive back an access token.

Can anyone tell me how I can get the request back from facebook and pull out the access token?

Thanks.

© Stack Overflow or respective owner

Related posts about ruby

Related posts about facebook