如何将Facebook App权限发布到Facebook页面(我拥有两者)?

时间:2014-09-07 23:40:40

标签: facebook-graph-api permissions

我不了解有关权限以及如何授予权限的重要信息。我做了一个Facebook页面,我做了一个应用程序。我希望该应用能够发布到页面。

以下是我的代码。我正在使用fb_graph ruby​​ gem,btw(https://github.com/nov/fb_graph

app = FbGraph::Application.new('531508086900000000', :secret => 'd705fda7275125913a10000000000')
token = app.get_access_token
page = FbGraph::Page.new('000000000000000')
note = page.note!( :access_token => token, :subject => 'testing', :message => 'Hey, testing you!')

这就是错误:

FbGraph::Unauthorized: OAuthException :: (#200) Requires extended permission: publish_actions

我在应用程序和页面设置上看到了我能想到的所有地方,但无法弄清楚如何执行此操作。帮助赞赏!

3 个答案:

答案 0 :(得分:1)

您需要通过用户访问令牌授予访问权限。 您的案例中的当前令牌是应用程序访问令牌。

使用https://developers.facebook.com/docs/facebook-login/permissions/v2.1#adding

中列出的方法之一

具体为https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow/v2.1#login

答案 1 :(得分:0)

我把phwd的答案投给了我在这里和IRC给我的帮助。但它仍然没有足够的信息来理解为什么这么难。我决定发布我目前对这是如何工作的工作理解。这些只是我自己的笔记,所以我很抱歉提前发现任何无法理解的事情。

So, getting the right access tokens is f***ing hard, and here's my current understanding:

In order to get a token that last forever so that my app can post to a page I have to do this:

1. Create a short-lived user access token with the right scope for the app (manage_pages, publish_actions) using the explorer
    - page access tokens can be obtained via /me/accounts from the explorer page
    - if the user access token that is "live" during the /me/accounts request is short lived then this page access token will be too
    - if it is an extended long-lived token the page access token will have no expiry according to https://developers.facebook.com/docs/facebook-login/access-tokens

2. Extend short-lived user access token to a long-lived one via a graph api call, also using exploer (see below)
3. Execute the /me/accounts call to get a page token that doesn't expire

 How to get a long lived user access token
   oauth/access_token?grant_type=fb_exchange_token&client_id=531------------&client_secret=e005f031ba3d98------------------&fb_exchange_token=CAAHjZA163IbMBAMKSeFTmeV9------------------------------------------------------------------------------------------------------------------------------------------------fonA4P4bPhhdveMLvZBKldEGCB7EvF301wQv1YPrudy5kvI
    where

    client_id          = App Id
    &client_secret     = App Secret
    &fb_exchange_token = short lived user access token via explorer with proper scope

 This gives you the following long lived access token
 access_token=CAAHjZA163Ib---------------------------------------------------------------------------------------------------------------------------------------------------------------------ehS8g2ZBYU8uZBPmdMay3AAj5tXgAZDZD&expires=5179843

 This is an extended user access_token
 This token can be used to post to the page it was genrated for.
 It can also be used to get a no-expiry page access token when used to issue /me/accounts

答案 2 :(得分:0)

来自facebook

页面访问令牌

这些访问令牌与用户访问令牌类似,不同之处在于它们为读取,写入或修改属于Facebook页面的数据的API提供权限。要获取页面访问令牌,您需要首先获取用户访问令牌并请求manage_pages权限。获得用户访问令牌后,您将get the page access token via the Graph API.