fb_graph post on a facebook group as a group member from rails app -
currently, i've rails app. if user authenticated facebook
can post on application. after post saved, rails app post user's post facebook group. possible?
i'm using fb_graph gem. , after user's post i've done after_create
callback post on facebook. here callback code:
def post_story_to_facebook if self.user.authentications.pluck(:provider).include?('facebook') page = fbgraph::group.new('ct.dhk.group') # group name # should declare user posting? page.feed!( :message => 'updating via fbgraph', :link => 'https://domain.tld', :name => 'pagename', :description => 'this test post deleted' ) end end
the above method not working , don't know how can post behalf of user?
we had similar working tested code. need store facebook_user_access_token
in user model (if don't have one, add new attribute, , update every time user gets authenticated through oauth, or if token renewed). see following.
post = post.find(1) # post facebook_page_id = '1234567890' # facebook group id facebook_user_access_token = current_user.facebook_user_access_token # current user's facebook user access token page = fbgraph::page.new(facebook_page_id) facebook_page_access_token = page.get_access_token(access_token: facebook_user_access_token) me = fbgraph::user.me(facebook_page_access_token) me.feed!( message: post.title, link: post_url(post), description: post.content, picture: post.main_image.url )
update:
haven't tested, looking @ this , this
suggests following work:
group = fbgraph::group.new(group_id) group.feed!({ access_token: user_access_token_with_proper_permissions, message: post.content })
unfortunately, not yet have time test things out. can try if work?
Comments
Post a Comment