views:

80

answers:

2

I am working on integrating Omniauth with my new Facebook application, and I am looking through the rather sparse documentation to understand if it gives simple ways to access the graph API... I am moving from Koala which was pretty simple.

Has anyone out there used Omniauth for this yet? I want to get photos from the users' albums, and sort and get the unique URLs for them.

A: 

I finally found out:

1) include this gem

2) use the gem:

user = FbGraph::User.new('me', :access_token => session[:omniauth]["credentials"]["token"])

user.fetch

3) retrieve your information user.name

Remember you can get anything from here ttp://developers.facebook.com/docs/reference/api/user

apnea.diving.deep
thanks - i will try this out... i have been trying to work with the code on here: http://bnerd.de/misc/ruby-write-basic-client-for-facebook-graph-api/ which certainly taught me a lot about the basics
Richard Jordan
the problem i get using the bnerd.de code is that Facebook's graph API calls seem to be returning 302 redirect not 200 ok http responses and i am not smart enough to rewrite bnerd's code to accommodate this.. i will attempt to use the FbGraph Gem and if I have better luck than you I'll post an update
Richard Jordan
I am getting uninitialized constant error for User::FBGraph - I am trying to call FBGraph from the User model creation function that I have... I added fb_graph to my gemsfile - not sure what else I could do to make sure it's working... any thoughts?
Richard Jordan
Well, nothing about your own User model. 'FbGraph::User' is built in the gem.
apnea.diving.deep
oh i get that... i was just adding context for the problem - i am calling FBGraph from within my User model before saving the new user object i want to pull data from the graph... but for some reason i am getting Uninitialized constant User::FBGraph error when i do this though :-(
Richard Jordan
ok :) I don't understand why you write User::FBGraph instead of FbGraph::User ;)
apnea.diving.deep
i don't write that
Richard Jordan
the error message is: 'uninitialized constant User::FBGraph' ...it is being called as an error on the following line in the User.rb file: " user = FBGraph::User.fetch(fbuid, :access_token => token) " ...where fbuid is an already created local variable with the fbuid of the user in it and token is the access token ...clearer?
Richard Jordan
User.rb line 20: user = FBGraph::User.fetch(fbuid, :access_token => token) ## generates an error message 'uninitialized constant User::FBGraph'
Richard Jordan
as I wrote above, I first create: user = FbGraph::User.new(fbuid, :access_token => token), then fetch it. But maybe the gem provides this direct method.
apnea.diving.deep
thanks - appreciate your help _ I am doing all of this but for some reason it won't work... meh - I found another solution and i'll post that below
Richard Jordan
A: 

So I wasn't able to get fb_graph to work properly - I am still a noob having been a Ruby On Rails developer for a total of about 8-10 weeks, and therefore don't have an instinct for what must be obvious problems to other folks.

However I found this great little blog post which outlines a simple facebook client and shows clearly how it all plugs together. I found an issue with it picking up the me/picture object as Facebook returns an http302 not http200 but that was easily worked around with the help of the author. Check it out: http://bnerd.de/misc/ruby-write-basic-client-for-facebook-graph-api/

I am now using Omniauth for the simplicity of the login/signup interaction based on this walkthrough here: blog.railsrumble.com/blog/2010/10/08/intridea-omniauth and with the token I get from that I am using this simple FBClient from the bnerd reference above to access the Graph API. Hope what I found helps others.

Richard Jordan