2017-05-26 70 views
1

我正在开发一个应用程序以订阅经过身份验证的用户的页面。 要测试应用程序,我使用测试用户(角色 - >测试用户)登录 此测试用户有两个主页。获取页面令牌以将我的应用程序订阅到用户的页面

弗里斯特,登录使用Facebook登录按钮,此范围内的用户:

“Public_profile,电子邮件,manage_pages,publish_pages,read_page_mailboxes,pages_show_list,pages_manage_cta,pages_manage_instant_articles”

我承认这一切的范围并检查登录状态:

   FB.getLoginStatus (function (response) { 
     If (response.status === 'connected') { 
        Console.log (response); 
      } 
   }); 

好吧,用access_token回应。

第二条显示用户的网页:

   FB.api (
      "/ Me/accounts", 
      Function (response) { 
        If (response &&! Response.error) { 
            Console.log (response); 
        } 
      } 
   ), {Scope: "manage_pages"}; 

而且我得到用户的网页烫发的的回复:

{ 
      "data": 
        [ 
          { 
            "Access_token": "token", 
            "Category": "Community", 
            "Name": "Procastinators", 
            "Id": "1692644001041745", 
            "Perms": [ 
              "ADMINISTER", 
              "EDIT_PROFILE", 
              "CREATE_CONTENT", 
              "MODERATE_CONTENT", 
              "CREATE_ADS", 
              "BASIC_ADMIN" 
            ] 
          }], 
      Paging 
        { 
          Cursors 
          {"Before": "MTY5MjY0NDAwMTA0MTc0NQZDZD", "after": "MjI5NTU0NjQwODY3NTYz"} 
        } 
    } 

最后我要订阅(这是必要page_token,最后调用):

``` 

      FB.api (
           "/ 229554640867563/subscribed_apps", 
          Function {response} { 
            If (response &&! Response.error) { 
              Console.log (response); 
            } 
          } 
      ); 

``` 

并且在最后一次调用订阅用户页面时,页面令牌获得d以前失败:

``` 

{ 
  "error": 
  { 
    "Message": "(# 210) A page access token is required to request this resource.", 
    "Type": "OAuthException", 
    "Code": 210, 
    "Fbtrace_id": "EVeyT8s \/Lgz" 
  } 
} 

``` 

如果某些步骤是缺少帮助我,我跟着这些指示:

  1. 登录:https://developers.facebook.com/docs/facebook-login/web#logindialog
  2. 验证状况:https://developers.facebook.com/docs/facebook-login/web/accesstokens
  3. 获取页面标记https://developers.facebook.com/docs/pages/access-tokens
  4. 已订阅:https://developers.facebook.com/docs/graph-api/reference/page/subscribed_apps

所有这些都处于开发模式,具有测试用户角色。

感谢您的时间。

+0

你如何订阅? – WizKid

+0

在'FB.api'中使用'scope'是没有任何意义的。而且你没有使用页面标记,否则我们会在你的API调用中看到一个名为'access_token'的参数。 – CBroe

+0

我有'access_token'来请求'page_token',但是page_token是** not ** returned – Luisangonzalez

回答

0

的问题是,你正在使用的令牌是不是在页面上一个,所以我要确保我使用的网页凭证

FB.api(
    "/1866825406900964?fields=access_token", 
    function(response) { 
    if (response && !response.error) { 
     page_access_token = response.access_token 
     FB.api(
     "/1866825406900964/subscribed_apps?access_token=" + page_access_token, 
     function(response) { 
      if (response && !response.error) { 
      console.log(response); 
      } 
     } 
    ); 
    } 
    } 
); 
相关问题