fb_graph post on a facebook group as a group member from rails app
Currently, I've a rails app. If user is authenticated with facebook then he can post something on my application. After the post was saved, my rails app will post the user's post to my facebook group. Is it possible?
I'm using fb_graph gem. And after the user's post I've done a after_create callback to post on facebook. Here is the callback code:
page = FbGraph::Group.new('ct.dhk.group') # group name
# where should I declare the user who is posting?
:message => 'Updating via FbGraph',
:link => 'https://domain.tld',
:name => 'PageName',
:description => 'This is a test post to be deleted'
The above method is not working and I don't know how can I post behalf of the user?
We had a similar working tested code. You need to store the facebook_user_access_token in your User model (if you don't have one, add a new attribute, and update that every time the user gets authenticated through OAuth, or only if token is renewed). See the following.
post = Post.find(1) # your post
facebook_page_id = '1234567890' # your Facebook group id
facebook_user_access_token = current_user.facebook_user_access_token # the 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)