ruby on rails - How to get user posts Insights from Facebook API Koala Gem -
hi wondering how user posts insights facebook api koala gem.
i found solutions works facebook page posts not user posts.
i used code below user posts returns empty array.
@graph.get_connections('me', 'insights', metric: 'page_impressions', period: 'now')
update
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)"]})
the code above works fine, when try post insights, returns empty array.
if using omniauth-facebook gem have make sure have right permissions in scope , can use original query.
config/initializers/omniauth.rb
omniauth.config.logger = rails.logger rails.application.config.middleware.use omniauth::builder provider :facebook, {id}, {secret}, :scope => 'email,manage_pages,read_stream,read_insights' end
also, can post insights page via koala. worked me.
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")