简体   繁体   English

如何管理在我的网站上经过Facebook身份验证的用户的页面?

[英]How do I manage pages of a user that facebook authed on my site?

I have an app that uses omniauth to facebook auth. 我有一个使用omniauth进行Facebook身份验证的应用程序。 I also have a user access token. 我也有一个用户访问令牌。 I'm using koala to access facebook graph api. 我正在使用考拉访问Facebook图形api。 However, I'm not sure how to pass koala my user access token to actually get access to the facebook pages that my user manages. 但是,我不确定如何向我的用户访问令牌传递考拉以实际访问我的用户管理的Facebook页面。

How do I get the pages that my user manages and pass the access token to do that? 如何获得用户管理的页面并传递访问令牌来做到这一点?

api = Koala::Facebook::API.new(access_token)

pages = api.get_connections(user_id, "accounts")

this returns the collection of pages for which your user has access, inside of each page there's an "access_token" property, that token is the one that you need to use to manage that specific page 这将返回您的用户有权访问的页面的集合,在每个页面的内部都有一个“ access_token”属性,该令牌是您用来管理该特定页面的令牌

Since you are using omniauth for Facebook Authentication, you can add scope: manage_pages while defining provider in omniauth.rb 由于您正在使用omniauth进行Facebook身份验证,因此可以在omniauth.rb定义提供程序时添加scope: manage_pages

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'], scope: 'publish_actions, email, manage_pages']
end

This will ask the user about the permissions required for managing pages. 这将询问用户管理页面所需的权限。

Now, when you have the permision, Use Koala to get a list of pages user has using a Graph API call 现在,当您有能力时,使用Graph API调用使用Koala获取用户拥有的页面列表

koala = Koala::Facebook::API.new(@access_token)

# retrieve collection fo all your managed pages: returns collection of hashes with page id, name, category, access token and permissions
pages = @user_graph.get_connections('me', 'accounts')

Use the access_token property from the result of the previous call. 使用上一次调用的结果中的access_token属性。

# get access token for first page
first_page_token = pages.first['access_token']

# or: retrieve access_token for a given page_id
page_token = @user_graph.get_page_access_token(page_id)

Use the page token to authenticate as a page and use Graph API as normal 使用页面令牌作为页面进行身份验证,并正常使用Graph API

@page_graph = Koala::Facebook::API.new(page_token)

@page_graph.get_object('me') # I'm a page
@page_graph.get_connection('me', 'feed') # the page's wall
@page_graph.put_wall_post('post on page wall') # post as page, requires new publish_pages permission
@page_graph.put_connections(page_id, 'feed', :message => message, :picture => picture_url, :link => link_url)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何让facebook页面管理员只选择他们希望我的应用管理的特定页面(manage_pages) - How do I allow a facebook page admin to select only the specific pages they want my app to manage(manage_pages) 在Oauth与facebook之后,如何获得用户创建的页面的图形? - After Oauth with facebook , how do I get the graph of the pages created by user? 如何在我的网站上提供内容以换取Facebook“喜欢” - How do I make content available on my site in exchange for a Facebook “like” 如何将我的Facebook应用程序用户与我的Web应用程序用户相关联? - How do I associate my facebook app user with my web app user? 如何在我的网站上更新用户的Facebook朋友? - How to update a user's friends from facebook on my site? 如何在客户端管理当前用户会话? - How do I manage the current user session on the client side? 如何跨git分支管理对数据库的更改? - How do I manage changes to my db across git branches? 如何在React组件中使用Facebook开发者网站上的Facebook登录按钮? - How do I use the Facebook Login Button from the Facebook Developers site in a React component? 如何安全,低成本地允许我的网站上的图像? - How do I allow safely and inexpensively allow images on my site? 如何将 HTML 页面转换为 Rails 站点上的页面? - How do I convert a page of HTML to a page on my Rails site?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM