如何用考拉搜索页面

how to search for pages with koala

我正在尝试使用 Koala gem 来搜索 facebook 页面,就像这样

@graph.get_connection('search', movie_name)

但是我得到了这个/Users/luizeduardo/.rbenv/versions/2.2.3/lib/ruby/2.2.0/uri/generic.rb:1100:in rescue in merge': bad URI(is not URI?): /search/Jurassic World (URI::InvalidURIError)

好像我用错了方法或者这不可能

看看

You can also search for users/pages/events/groups for the keyword of your choice:

# http://graph.facebook.com/search?q=koala&type=place
@graph.get_connection('search', type: :place)
# => [{"category"=>"Attractions/things to do", ...
#     "name"=>"Maru Koala & Animal Park"}]}

在你的情况下,这意味着

@graph.get_connection('search', type: :page)

恕我直言...

您使用 get_connection 似乎是对 public 页面数据进行一般搜索的不正确方法。 get_connection与FB朋友网有更多关系。要更详细地了解 API 调用 Koala 将进行的操作,请查看代码,其中有很好的注释描述了每种方法的工作原理。对于一般的 API 图形调用,您可以简单地使用 graph_call 方法。

https://github.com/arsduo/koala/blob/master/lib/koala/api/graph_api.rb

您应该能够使用 graph_call 方法并传入任何 api 调用作为字符串中的单个参数。

fb = Koala::Facebook::API.new(ENV['FACEBOOK_CLIENT_TOKEN'])
lookup = fb.graph_call("search?q=star%20wars%20movie&type=page")

see similar question and answer here

get_connection 也对我抛出同样的错误(可能是因为 v2.6?)。

无论如何,我发现解决方案有效:

@graph.get_object('search?q=YOUR_QUERY&type=page')

Koala Wiki 应该这样说: @graph.search('koala', type: :place)

而不是这个: @graph.get_connection('search', type: :place)

希望这能让您更接近解决方案。