#361 Facebook Graph API pro
Learn how to use the Facebook Graph API with the Koala gem to fetch data from Facebook and post content through a user. Here I delve into permissions, error handling, and more.
- Download:
- source code
- mp4
- m4v
- webm
- ogv
Wow, this is really great! Very nice screencast, Ryan; it's neat to see how easily it can be done!
A little OT, but I was amazed at the number of columns and amount of data in the User table. They pretty much keep everything there...At first I thought that would be a tremendous amount of overhead to get that much data every time you want to query a simple user attribute...?
But, on second thought, they probably store the entire User table in some gigantic memory cache.
Anyway, neat stuff!
Perhaps what we're getting is just a nice abstraction, and they store things quite differently behind the scenes.
Great episode
When last month fb revoked the offline-access token perms, I had several rework in my apps.
In which way do you managed this?
https://developers.facebook.com/roadmap/offline-access-removal/
Somebody has an example?
In next railscasts you will cover this?
The problem is, I want to post something in user wall while he uses my app throught a mobile api, for example. If the accesstoken user stored when he logged first time expire, how did you manage this case?
(sorry for my terrible english)
Nunzio
what do you think about an aproach like this?
if $('#sign_out').length > 0
FB.getLoginStatus (response) ->
if !response.authResponse
FB.login (response) ->
window.location = '/auth/facebook/callback' if response.authResponse
, scope: "email,publish_stream"
I ve got the solution, what do you think about that
application.html.erb
facebook.js.coffee.erb
In this way when auth token is expired but user is connected you have an automatic relogin client side.
Curious for your opinion
Bye
Nunzio
Great episode! Does anybody know how to set the actions field as mentioned on https://developers.facebook.com/docs/reference/api/post/ when submitting a post to the users feed.
Great job in this railscast!
I was hoping that Facebook lets a user export their friends' email addresses to external apps so that a user can see which of his/her other friends are already using that app. Facebook doesn't allow this, for better or worse (probably to maintain control and to prevent spam).
The above functionality of helping a user find their Facebook friends on your app can still be accomplished, but it requires that both users go through the trouble of connecting their Facebook accounts to your app. This is a significant barrier, I believe.
Fortunately, I found that OmniContacts enables a user to import their email contacts directly to your app: https://github.com/Diego81/omnicontacts/
This is a great idea for a new Railscast! Maybe Ryan could show us how to import contacts using OmniContacts or any other gem he believes is the most suitable.
Thanks for this episode. It's very clearly, but I have some error on this episode.
I asked on stackoverflow, but there're no one can answer me. Hope can help me. Thanks!
http://stackoverflow.com/questions/11793788/gem-koala-undefined-methods-get-object
UGH!!! I clean installed Mountain Lion, installed Rails Installer and now when I follow this tutorial, I get this:
Faraday::Error::ConnectionFailed
SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
Koala.http_service.http_options = {
:ssl => { :ca_path => "/etc/ssl/certs" }
}
That ca_path is a path to your system wide ca_certs, in Ubuntu they are located at /usr/lib/ssl/certs.
i get this on the very next page after the user signs up using fb using the oauth fb video tutorial here (and devise oauth).
this error is triggered by
= current_user.facebook.get_object("me").to_yaml
anybody dealt with this?
OAuthException: Error validating access token: Session has expired at unix time 1345496400. The current unix time is 1345499103.
Just digging into Koala and using it to create feed posts to a page. I can successfully create a post with the below, but struggling to make the update work.
INSERT CODE SNIPPET - Works great and returns post id from fb
UPDATE CODE SNIPPET - fb returns true, but not reflecting updates on fb page when refreshed
Any thoughts on where I'm going wrong?
Very useful.. thanks
If you're using chrome you don't actually need to open a different browser to test, you can just hit cmd+shift+n to open a new incognito window and log in as your test user there.
trying to find user friends who are using my app using koala gem but I am facing these issue and I didnot find any solution for it
Koala::Facebook::AuthenticationError in Reg_steps#show
type: OAuthException, code: 190, error_subcode: 460, message: Error validating access token: Session does not match current stored session. This may be because the user changed the password since the time the session was created or Facebook has changed the session for security reasons. [HTTP 400]
I was getting the same thing. You have to sign out of that user and maybe delete the db record. You've updated some permissions and the token is now invalid. Once you do that and re-authenticate, you should be good. Worked for me.
I'm trying to duplicate the "logged out of FB" error Ryan gets, and I can't. My app won't crash!
Did Facebook do anything to fix that?
Thanks! I don't want to add the error-rescuing code if I don't have to.
I get this error after putting in the rescue code(which does not work for me)
"SyntaxError: missing ", starting #line 7 .." in my facebook.js.coffee.erb file. Obviously that is not where the syntax error is and it is triggered by somethings else but I cannot find it.
Anyone an idea why the rescue won't work? Everything else in the episode before the rescue part works but not after.
thanks
This page gives you a lot of information. Thank you!