【问题标题】:Get a page token to subscribe my application to the users' pages获取页面令牌以将我的应用程序订阅到用户页面
【发布时间】:2017-10-27 17:52:08
【问题描述】:

我正在开发一个应用程序来订阅在其中经过身份验证的用户的页面。 为了测试应用程序,我使用测试用户登录(角色 --> 测试用户) 这个测试用户有两个主页。

首先,使用具有此范围的 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);
            }
          }
      );

```

在最后一次调用订阅用户页面时,之前获得的页面令牌失败:

```

{
  "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

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

感谢您的宝贵时间。

【问题讨论】:

  • 如何订阅?
  • scopeFB.api 一起使用毫无意义。而且您没有使用页面令牌,否则我们会在您的 API 调用中看到一个名为 access_token 的参数。
  • 我有access_token 来请求page_token,但是page_token 没有返回
  • 我使用的 access_token 不是 page_token,我现在保存 page_access 进行订阅。

标签: javascript facebook facebook-graph-api token facebook-page


【解决方案1】:

问题是您使用的令牌不是页面上的令牌,所以我确保我使用了页面令牌

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);
          }
        }
      );
    }
  }
);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-05
    • 2020-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多