Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>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.</p> <p>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: <a href="http://bnerd.de/misc/ruby-write-basic-client-for-facebook-graph-api/" rel="nofollow">http://bnerd.de/misc/ruby-write-basic-client-for-facebook-graph-api/</a></p> <p>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.</p> <p>...here's my version of bnerd's code and it worked for me:</p> <pre><code> class FBClient def initialize(app, access_token = nil) @app = app @access_token = access_token end # request permission(s) from user def request(perms) #create a random verifier to identify user on fb callback verifier = (0...10).map{65.+(rand(25)).chr}.join uri = "https://graph.facebook.com/oauth/authorize?client_id=#{@app.app_id}&amp;redirect_uri=#{@app.connect_url}?verifier=#{verifier}&amp;scope=#{perms}" request = { :verifier =&gt; verifier, :uri =&gt; uri } return request end def connect(code, verifier) uri = URI.parse("https://graph.facebook.com/oauth/access_token?client_id=#{@app.app_id}&amp;redirect_uri=#{@app.connect_url}?verifier=#{verifier}&amp;client_secret=#{@app.secret}&amp;code=#{CGI::escape(code)}") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Get.new(uri.path + "?" + uri.query) response = http.request(request) data = response.body return data.split("=")[1] end # get, post def get(path, params = nil) uri = URI.parse("https://graph.facebook.com/" + path) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true if params.nil? params = Hash.new end if params["access_token"].nil? params["access_token"] = @access_token unless @access_token.nil? end request = Net::HTTP::Get.new(uri.path) request.set_form_data( params ) request = Net::HTTP::Get.new(uri.path + "?" + request.body) return response = http.request(request) end def post(path, params = nil) uri = URI.parse("https://graph.facebook.com/" + path) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true if params.nil? params = Hash.new end if params[:access_token].nil? params[:access_token] = @access_token unless @access_token.nil? end request = Net::HTTP::Post.new(uri.path) request.set_form_data( params ) request = Net::HTTP::Post.new(uri.path + "?" + request.body) response = http.request(request) response.code == "200" ? feed = JSON.parse(response.body) : raise("Sorry, an error occured. #{response.body}") return feed end end </code></pre> <p>I am sure someone more experienced than I could improve this - I was about 10 weeks into learning Ruby (and my first programming since Fortran and Pascal at university in the early 90s!).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload