嗨,我想知道如何从Facebook API Koala Gem获得用户帖子洞察。
我只找到了适用于facebook页面帖子的解决方案,而不是用户帖子。
我对用户帖子使用了下面的代码,但它只返回空数组。
@graph.get_connections('me', 'insights', metric: 'page_impressions', period: 'now')更新
user = Authentication.where(user_id: current_user.id, provider: "facebook").first
oauth_access_token = user.token
@graph = Koala::Facebook::API.new(oauth_access_token)
@posts = @graph.get_connection('me', 'posts',{ fields: ['id', 'message', 'link', 'name', 'description', "likes.summary(true)", "shares", "comments.summary(true)"]})上面的代码运行良好,但当我尝试获取post洞察时,它返回空数组。
发布于 2015-07-18 11:23:59
如果您使用omniauth-facebook gem,您只需确保在您的作用域中拥有正确的权限,并且可以使用原始查询。
config/initializers/omniauth.rb
OmniAuth.config.logger = Rails.logger
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, {id}, {secret},
:scope => 'email,manage_pages,read_stream,read_insights'
end此外,你还可以通过考拉获得页面的帖子洞察力。这对我很有效。
m = Koala::Facebook::API.new(User.find(5).oauth_token)
m = m.get_connections('me', 'accounts')
m = m.first['access_token']
@post_graph = Koala::Facebook::API.new(m)
@feed = @post_graph.get_connection('me', 'feed')
@postid = @feed.first['id']
@post_data = @post_graph.get_connections(@postid, 'likes', since: "2015-05-17", until: "2015-07-17")发布于 2015-04-23 14:50:43
https://developers.facebook.com/docs/graph-api/reference/v2.3/post
如果你在“边缘”处查看这里,你可以看到/insights只对页面可用。
‘/这篇文章的洞察力(仅适用于页面)’
我希望我是对的,并帮助了你。
发布于 2015-05-06 21:20:53
Here你可以看到它只用于页面发布
/{post-id}/insights (其中这是一个页面帖子)
https://stackoverflow.com/questions/29813725
复制相似问题