gpt4 book ai didi

javascript - 获取页面 token 以将我的应用程序订阅到用户页面

转载 作者:行者123 更新时间:2023-11-28 04:35:55 24 4
gpt4 key购买 nike

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

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

```

在最后一次调用订阅用户页面时,使用之前获取的页面 token 会失败:

```

{
  "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. 获取页面 token https://developers.facebook.com/docs/pages/access-tokens
  4. 已订阅:https://developers.facebook.com/docs/graph-api/reference/page/subscribed_apps

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

感谢您的宝贵时间。

最佳答案

问题是您使用的 token 不是页面上的 token ,因此我确保使用页面 token

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

关于javascript - 获取页面 token 以将我的应用程序订阅到用户页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44208298/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com