nov / fb_graph

This gem doesn't support FB Graph API v2.0+. Please use fb_graph2 gem instead.
MIT License
1.04k stars 191 forks source link

FQL query error #314

Closed Goltergaul closed 11 years ago

Goltergaul commented 11 years ago

i've got this query:

notifications = FbGraph::Query.new(
      "SELECT notification_id, sender_id, title_text, body_text, href, object_id, object_type
      FROM notification
      WHERE recipient_id=#{fb_uid} AND is_unread = 1 AND is_hidden = 0"
    ).fetch(fb_user.access_token)

and it throws the following error:

TypeError: can't convert Symbol into Integer from /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/fb_graph-2.7.0/lib/fb_graph/query.rb:24:in []' from /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/fb_graph-2.7.0/lib/fb_graph/query.rb:24:inbuild_params' from /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/fb_graph-2.7.0/lib/fb_graph/query.rb:12:in block in fetch' from /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/fb_graph-2.7.0/lib/fb_graph/query.rb:30:inblock in handle_response' from /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/fb_graph-2.7.0/lib/fb_graph/node.rb:123:in handle_response' from /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/fb_graph-2.7.0/lib/fb_graph/query.rb:29:inhandle_response' from /home/gaul/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/fb_graph-2.7.0/lib/fb_graph/query.rb:11:in `fetch'

I did some debugging in the query class, the instance looks like this (access_token missing)

<FbGraph::Query:0x00000004c1eb08 @identifier="fql", @endpoint="https://graph.facebook.com/fql", @access_token=nil, @raw_attributes={:access_token=>nil}, @cached_collections={}, @query="SELECT notification_id, sender_id, title_text, body_text, href, object_id, object_type\n          FROM notification\n          WHERE recipient_id=100005849799769 AND is_unread = 1 AND is_hidden = 0">

instead the acces_token is directly passed as the params argument in, which results in the error above on params[:access_token]:

def build_params(params)
  _query_ = if query.is_a?(Hash)
    query.to_json
  else
    query
  end
  params[:access_token] ||= self.access_token
  super params.merge(:q => _query_)
end
Goltergaul commented 11 years ago

passing the access token as :access_token => "token" fixes the issue. please update the gist in the wiki.

notifications = FbGraph::Query.new(
      "SELECT notification_id, sender_id, title_text, body_text, href, object_id, object_type
      FROM notification
      WHERE recipient_id=#{fb_uid} AND is_unread = 1 AND is_hidden = 0"
    ).fetch(:access_token => fb_user.access_token)
nov commented 11 years ago

Thanks for your report. I just updated the wiki. https://github.com/nov/fb_graph/wiki/FQL