【问题标题】:Facebook Messenger Platform -> Subscribed Apps with graph-api not working for meFacebook Messenger Platform -> 使用 graph-api 订阅的应用程序不适合我
【发布时间】:2017-03-22 18:58:41
【问题描述】:

我正在尝试为我的机器人开发一键集成支持,其中包括 FB Messenger。 对于 FB 信使,我做了以下操作:

  1. 按照“quick-start”指南创建了一个 Facebook 应用程序。
  2. 遵循“facebook-login”教程并部署了一个 facebook 登录进程,该进程具有以下权限: - public_profile - 电子邮件 - 管理页面 - pages_show_list - pages_messaging_subscriptions - pages_messaging
  3. 然后我使用 '/me/accounts' 的 graph-api 来获取我在 facebook 中创建的“测试用户”下的页面名称、页面 ID 和 access_token 列表。
  4. 现在,我在这个“测试用户”(拥有所有权限)下选择了一个页面,并尝试运行这个 JS 代码 -

FB.api(
      `/${page.id}/subscribed_apps?access_token=${page.access_token}`,
      function (response) {        
        console.log(`response = {$JSON.stringify(response)}`);
        if (response && !response.error) {          
          /* handle the result */
        }
      }
    );

问题:我得到 response = {"data":[]} ,这可能没问题,但是当我查看 page->settings->Messenger Platform->Subscribed Apps 时,我没有看到任何应用在那里订阅。 顺便说一句,当我在没有正确 access_token 的情况下运行它时,我确实收到了错误 #210 ("needs access_token"),这与预期的一样......

知道如何将应用程序正确订阅到页面吗? 必须说我也用graph api explorer工具尝试过,得到了同样的结果......

提前致谢:-)。

【问题讨论】:

  • 需要是POST请求。
  • 嘿@CBroe - 感谢您的帮助。工作:-)。

标签: facebook-graph-api facebook-messenger


【解决方案1】:

@CBroe 正确,有 2 个问题: 1. 我应该使用 POST() 而不是 GET() 方法。 2.当你使用graph-api-explorer工具时,你会看到它可以工作,然后角色下降并获取JS代码......问题是代码有点混乱,因为你得到的是这样的:

FB.api(
  `/${my_page_id}/subscribed_apps`,
  'POST',
  {},
  function(response) {
      // Insert your code here
  }
);

但是,实际上应该是这样的:

FB.api(
  `/${my_page_id}/subscribed_apps`,
  'POST',
  {"access_token": `${page_access_token}`},
  function(response) {
      // Insert your code here
  }
);

如我在问题中所述,请记住从 /me/accounts api 获取 access_token。

再次感谢 @CBroe 向我展示了如何解决这个问题 :-)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多