Ruby——使用facebook';s图形API浏览器与考拉宝石

Ruby——使用facebook';s图形API浏览器与考拉宝石,ruby,facebook-graph-api,rubygems,oauth-2.0,koala,Ruby,Facebook Graph Api,Rubygems,Oauth 2.0,Koala,我发现facebook的“Graph API Explorer”工具()是一种非常简单的方法,欢迎(对于初学者)通过GUI使用facebook的Graph API,这是一种有效的方法 我希望能够使用考拉宝石将这些生成的URL传递到facebook的api 现在,假设我有一个这样的问题 url = "me?fields=id,name,posts.fields(likes.fields(id,name),comments.fields(parent,likes.fields(id,name)),m

我发现facebook的“Graph API Explorer”工具()是一种非常简单的方法,欢迎(对于初学者)通过GUI使用facebook的Graph API,这是一种有效的方法

我希望能够使用考拉宝石将这些生成的URL传递到facebook的api

现在,假设我有一个这样的问题

url = "me?fields=id,name,posts.fields(likes.fields(id,name),comments.fields(parent,likes.fields(id,name)),message)"
我希望能够把它作为一根绳子直接传给考拉

@graph.get_connections(url)
它不喜欢这样,所以我将uid和
操作符分开,就像gem希望的那样

url = "fields=id,name,posts.fields(likes.fields(id,name),comments.fields(parent,likes.fields(id,name)),message)"
@graph.get_connections("me", url)
但是,这也会返回一个错误:

Koala::Facebook::AuthenticationError: 
type: OAuthException, code: 2500, 
message: Unknown path components: /fields=id,name,posts.fields(likes.fields(id,name),comments.fields(parent,likes.fields(id,name)),message) [HTTP 400]
目前这就是我被困的地方。我想继续使用考拉,因为我喜欢使用gem方法来处理API,尤其是在使用OAuth和OAuth2时

更新:

例如,我开始将请求分解为考拉宝石可以处理的部分

posts = @graph.get_connections("me", "posts")
postids = posts.map { |p| p['id'] }
likes = postids.inject([]) {|ary, id| ary << @graph.get_connection(id, "likes") }
posts=@graph.get_连接(“我”、“posts”)
postids=posts.map{| p | p['id']}

likes=postids.injection([]){ary,id | ary我真的不知道你的
posts.fields(likes.fields(id,name)
——这在中不起作用——诸如此类的东西,但我知道你可以做到:

fb_api = Koala::Facebook::API.new(access_token)
fb_api.api("/me?fields=id,name,posts")
# => => {"id"=>"71170", "name"=>"My Name", "posts"=>{"paging"=>{"next"=>"https://graph.facebook.com/71170/posts?access_token=CAAEO&limit=25&until=13705022", "previous"=>"https://graph.facebook.com/711737070/posts?access_token=CAAEOTYMZD&limit=25&since=1370723&__previous=1"}, "data"=>[{"id"=>"71170_1013572471", "comments"=>{"count"=>0}, "created_time"=>"2013-06-09T08:03:43+0000", "from"=>{"id"=>"71170", "name"=>"My Name"}, "updated_time"=>"2013-06-09T08:03:43+0000", "privacy"=>{"value"=>""}, "type"=>"status", "story_tags"=>{"0"=>[{"id"=>"71170", "name"=>"  ", "length"=>8, "type"=>"user", "offset"=>0}]}, "story"=>"  likes a photo."}]}}

你会收到你要求的内容。

我真的不知道你的
posts.fields(likes.fields(id,name)
——这在中不起作用,但我知道你可以做到:

fb_api = Koala::Facebook::API.new(access_token)
fb_api.api("/me?fields=id,name,posts")
# => => {"id"=>"71170", "name"=>"My Name", "posts"=>{"paging"=>{"next"=>"https://graph.facebook.com/71170/posts?access_token=CAAEO&limit=25&until=13705022", "previous"=>"https://graph.facebook.com/711737070/posts?access_token=CAAEOTYMZD&limit=25&since=1370723&__previous=1"}, "data"=>[{"id"=>"71170_1013572471", "comments"=>{"count"=>0}, "created_time"=>"2013-06-09T08:03:43+0000", "from"=>{"id"=>"71170", "name"=>"My Name"}, "updated_time"=>"2013-06-09T08:03:43+0000", "privacy"=>{"value"=>""}, "type"=>"status", "story_tags"=>{"0"=>[{"id"=>"71170", "name"=>"  ", "length"=>8, "type"=>"user", "offset"=>0}]}, "story"=>"  likes a photo."}]}}

您将以散列形式收到您请求的内容。

您必须不时将nil作为参数传递给考拉:

result += graph_api.batch do |batch_api|
  facebook_page_ids.each do |facebook_page_id|
    batch_api.get_connections(facebook_page_id, nil, {"fields"=>"posts"})
  end
end

有时,您必须将nil作为参数传递给考拉:

result += graph_api.batch do |batch_api|
  facebook_page_ids.each do |facebook_page_id|
    batch_api.get_connections(facebook_page_id, nil, {"fields"=>"posts"})
  end
end

您没有获取整个查询。完整查询是
me?fields=id,name,posts.fields(likes.fields(id,name),comments.fields(parent,likes.fields(id,name)),message)
它确实有效。我只是尝试了一下。我当时不知道你可以这么做。谢谢!如果你正在做一个批处理,你可能会想知道:result+=graph_api.batch do | batch_api | facebook|page_id | batch_api.get_connections(facebook_page_id,nil,{“fields”=>posts})end end您没有获取整个查询。完整查询是
me?fields=id,name,posts.fields(likes.fields(id,name),comments.fields(parent,likes.fields(id,name)),message)
它确实有效。我只是尝试了一下。我当时不知道你可以这么做。谢谢!如果你正在做一个批处理,你可能会想知道:result+=graph_api.batch do | batch_api | facebook|page_id | batch_api.get_connections(facebook_page_id,nil,{“fields”=>posts})结束