Facebook Messenger订阅的应用程序,页面和应用程序访问令牌生成 [英] Facebook Messenger subscribed apps, page and app access token generation

查看:120
本文介绍了Facebook Messenger订阅的应用程序,页面和应用程序访问令牌生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开发与我的机器人的Facebook页面无缝集成时,我遇到了麻烦.

I am hitting a wall while developing seamless integration of a Facebook page with my bot.

本质上,我想实现与Chatfuel或Manychat相同的集成,在这里使用您的Facebook帐户登录后,您可以选择要连接到他们的页面,并且一切正常.

Essentially I want to achieve same integration than Chatfuel or Manychat have, where being logged in with your Facebook account lets you to just choose what page you are connecting to them and you are good to go.

我面临的问题是生成正确的令牌,以便将所选页面绑定到我的应用程序(机器人).根据Facebook文档:

The problem I am facing is generating the proper token in order to bind the selected page to my app (bot). As per Facebook documentation:

在创建subscribed_apps边缘时,在端点中使用的页面ID必须与API调用中使用的页面访问令牌的页面ID相匹配.该页面已安装访问令牌所针对的应用.

鉴于该呼叫除了访问令牌外没有其他参数,因此该访问令牌必须足以让Facebook执行以下操作:

Given the call has no other parameter than the access token, this access token has to be enough for Facebook to:

  1. 授权页面上的操作.
  2. 识别正在订阅该页面的应用程序.

在使用 Facebook Graph API Explorer (其中选择页面)时已确认并绑定应用,并生成正确的访问令牌:

This is confirmed while using the Facebook Graph API Explorer, where one selects the page and the app to bind and a proper access token is generated:

此令牌可在终端中使用cURL正常工作:

This token properly works using cURL in the terminal:

$ curl -X POST 'https://graph.facebook.com/v3.0/<MY_APP_ID_HERE>/subscribed_apps?access_token=<TOKEN_PASTED_FROM_GRAPH_API_EXPLORER>'
{"success":true}

使用Facebook Access令牌调试器(访问令牌左侧的信息图标,然后在访问令牌工具中打开),确认该令牌同时知道该页面和该应用程序必须连接.

With the Facebook Access token debugger (info icon on the left of the access token, then open in Access token tool), it is confirmed that the token knows about both the page and the app that have to be connected.

问题是,这些与页面应用程序相关的令牌是如何以编程方式生成的?我似乎在Facebook文档中找不到正确的API调用,而且它绝对有可能,因为Chatfuel和Manychat正在这样做.

The question is, how are these page-app related token programmatically produced? I can't seem to find the proper API call in Facebook documentation and it is by all means possible, as Chatfuel and Manychat are doing this.

提前感谢您的支持施瓦茨夫人和社区!

Thanks in advance for your support Lars Schwarz and community!

推荐答案

在Alex的答案中添加一些细节,以使其更加完整.

Adding some detail to Alex's answer, for it to be more complete.

在将应用程序订阅到页面时,Facebook需要:

When subscribing an app to a page, Facebook needs to:

  1. 了解您在谈论什么应用.
  2. 知道您在说什么页面.
  3. 知道您在该页面上具有订阅应用程序的权限.

Facebook如何知道这一切?

How does Facebook know it all?

1 来自Facebook登录发生在页面上下文中的事实,实际上,Facebook的Javascript代码包含您的appId:

1 comes from the fact that Facebook login happens in the context of a page, actually, the Javascript code for Facebook contains your appId:

js.src = 'https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v3.0&appId=<YOUR_APP_ID_IS_HERE>&autoLogAppEvents=1';

2 来自用于将应用程序订阅到页面的URL中的page_id:

2 Comes from the page_id in the URL used to subscribe apps to pages:

https://graph.facebook.com/v3.0/ YOUR_APP_ID_HERE /subscribed_apps?access_token = YOUR_ACCESS_TOKEN_HERE

https://graph.facebook.com/v3.0/YOUR_APP_ID_HERE/subscribed_apps?access_token=YOUR_ACCESS_TOKEN_HERE

3 来自访问令牌,该访问令牌是通过Facebook登录在APP的上下文中获得的,该访问令牌作为用于向页面订阅应用的URL中的参数传递的:

3 Comes from the access token, obtained in the context of an APP through Facebook login, that is passed as parameter in the URL used to subscribe apps to pages:

> https://graph.facebook.com/v3.0/YOUR_APP_ID_HERE/subscribed_apps?access_token = YOUR_ACCESS_TOKEN_HERE

这篇关于Facebook Messenger订阅的应用程序,页面和应用程序访问令牌生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆