- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
OBSERVE https://developers.facebook.com/docs/chat/
The service and API this document covers has been deprecated with the release of Platform API v2.0. Once version 1.0 is deprecated, chat.facebook.com will no longer be available.
Important! Read this and you probably want to do something completely different than anything that has to do with this question.
我正在使用连接到 Facebook 聊天 API 的 WebForms C# 创建聊天。
我也看过this SO question (和所有链接)。有些部分不再相关,因为 Facebook 现在需要 auth_token
。
要复制它,您应该设置一个 Facebook 网络应用程序,使用 appId
和一个具有 xmpp_login 权限集的用户帐户。然后创建一个包含代码的 Chat.aspx
并相应地粘贴此代码。并替换硬编码的用户进行交互。
我有两个(也许三个)问题,我认为这些问题阻止我成功实现发送聊天消息的目标。
//finishes auth process
的过程与 documentation description 不匹配(在收到来自 Facebook 的基于 SSL/TLS 的成功消息后,我没有收到任何回复。)Here is my code in its entirety, on PasteBin .
我还有一些用于添加 xmpp_login 权限等的助手。为清楚起见,已将其删除。
全局变量:
public partial class Chat : Page
{
public TcpClient client = new TcpClient();
NetworkStream stream;
private SslStream ssl;
private string AppId { get; set; }
public string AppSecret { get; set; }
public string AppUrl { get; set; }
public string UserId { get; set; }
public string AccessToken { get; set; }
private string _error = string.Empty;//global error string for watch debugging in VS.
public const string FbServer = "chat.facebook.com";
private const string STREAM_XML = "<stream:stream xmlns:stream=\"http://etherx.jabber.org/streams\" version=\"1.0\" xmlns=\"jabber:client\" to=\"chat.facebook.com\" xml:lang=\"en\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\">";
private const string AUTH_XML = "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='X-FACEBOOK-PLATFORM'></auth>";
private const string CLOSE_XML = "</stream:stream>";
private const string RESOURCE_XML = "<iq type=\"set\" id=\"3\"><bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\"><resource>fb_xmpp_script</resource></bind></iq>";
private const string SESSION_XML = "<iq type=\"set\" id=\"4\" to=\"chat.facebook.com\"><session xmlns=\"urn:ietf:params:xml:ns:xmpp-session\"/></iq>";
private const string START_TLS = "<starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\"/>";
然后在 Page_Load
中执行(或应该)执行所有必需的步骤。值得注意的是 SendMessage("test");
。我只是想把它放在那里看看它是否能成功发送聊天消息... SetUserNameAndAuthToken
将我的身份验证 token 和用户名设置为全局变量。 AuthToken 有效。
protected void Page_Load(object sender, EventArgs e)
{
this.AppId = "000000082000090";//TODO get from appsettings.
//AddAdditionalPermissions("xmpp_login");//TODO handle xmpp_login persmission
this.AppSecret = "d370c1bfec9be6d9accbdf0117f2c495"; //TODO Get appsecret from appsetting.
this.AppUrl = "https://fbd.anteckna.nu";
SetUserNameAndAuthToken();
Connect(FbServer);
// initiates auth process (using X-FACEBOOK_PLATFORM)
InitiateAuthProcess(STREAM_XML);
// starting tls - MANDATORY TO USE OAUTH TOKEN!!!!
StartTlsConnection(START_TLS);
// gets decoded challenge from server
var decoded = GetDecodedChallenge(AUTH_XML);
// creates the response and signature
string response = CreateResponse(decoded);
//send response to server
SendResponseToServer(response);
SendMessage("test");
// finishes auth process
FinishAuthProcess();
// we made it!
string streamresponseEnd = SendWihSsl(CLOSE_XML);
}
所以我得到一个响应,然后我将响应发送到服务器:
private void SendResponseToServer(string response)
{
string xml = String.Format("<response xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\">{0}</response>", response);
string response2 = SendWihSsl2(xml);
if (!response2.ToLower().Contains("success"))
_error = response2;
}
这需要 1 分 40 秒...响应是:
<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>
最后我执行了 FinishAuthPorcess()
private void FinishAuthProcess()
{
string streamresponse = SendWithSsl(STREAM_XML);
if (!streamresponse.Contains("STREAM:STREAM"))
_error = streamresponse;
string streamresponse2 = SendWihSsl(RESOURCE_XML);
if (!streamresponse2.Contains("JID"))
_error = streamresponse2;
string streamresponse3 = SendWihSsl(SESSION_XML);
if (!streamresponse3.Contains("SESSION"))
_error = streamresponse2;
}
所有响应都是""
。查看 SendWithSsl
中的 Read
方法:它是 0 个字节。尝试发送消息也给我 0 字节从 Facebook 读取数据。我不知道为什么?
最佳答案
现在有新的api。Messenger 平台如何运作?当用户在 Messenger 上向企业发送消息时,只要此主页使用应用程序部分或完全自动化对话,就会发生以下情况。 Facebook 服务器将 webhook 发送到托管消息应用程序的业务服务器的 URL。使用发送 API,应用程序可以在 Messenger 上回复用户。通过这种方式,开发者可以构建引导式对话以引导人们完成自动化流程,或者构建一个应用程序作为您的代理和您在 Messenger 上的业务存在之间的桥梁。
使用 Messenger 平台不需要支付任何费用。它旨在让企业处理客户的查询。一旦您为客户建立了互动体验,您就可以利用广告将人们带到您的体验中,例如点击信使广告或收件箱广告。
Messenger for Business 体验是什么样的?我们有一个示例电子商务业务,您可以在 Messenger 上与之聊天,名为 Original Coast Clothing。
在这里与示例业务聊天
我该如何开始?您可以先创建一个测试页面和测试应用程序,让您在 Messenger 中体验您的体验。我们有一些示例可以帮助您入门。一旦您的应用程序准备好部署,您就可以提交它以供审核。当您的应用通过我们的审核流程后,就可以与公众互动了。
为了开始,您需要 Messenger、一个 Facebook 页面和一个要将 webhook 发送到的 url。
这是将上述体验部署到测试页以帮助您入门的分步指南。
准备好 build 了吗?开始吧
https://developers.facebook.com/products/messenger/
https://developers.facebook.com/docs/messenger-platform/reference/send-api/
关于c# - 通过 Facebook 聊天 API (XMPP) C# 发送消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19590752/
我正在使用 voip 推送通知制作 ios 应用程序。 我想从 Node js 发送 voip 推送通知,但不是很好。 我阅读了本教程 CallKit iOS Swift Tutorial for V
我编写了一个服务器,当浏览器尝试连接到某些站点时,它会检查黑名单并发回 404,但是当我调用 send() 时没有错误,但消息不会出现在网络上浏览器,除非我关闭连接? 有什么建议吗? 接受来自浏览器的
#include int main() { char c = getchar(); //EOF (ctrl + d ) while( ( c = getchar() ) != '?'
我正在尝试使用MailMessage对象通过PowerShell发送电子邮件。该脚本使用Import-CSV来使用文件,然后在电子邮件正文中使用ConvertTo-HTML。由于我要发送的电子邮件客户
我需要创建一个脚本,每 30 秒对网络流量进行一次采样并存储发送/接收的字节。该数据随后用于绘制图形。我编写了一个在 Windows 2012 上完美运行的程序,但我意识到某些 cmdlet 在以前的
我正在运行“autoit3.chm”文件。当它运行时,我想发送一个向下键箭头,但它不起作用: $file = FileGetShortName("C:\Users\PHSD100-SIC\Deskto
当我使用网络浏览器测试我的程序时,我可以很好地写入套接字/FD,所以我决定循环它并在连接中途切断连接,我发现了一个问题。 send() 能够在套接字不可用时关闭整个程序。我认为问题在于该程序陷入了第
我正在运行“autoit3.chm”文件。当它运行时,我想发送一个向下键箭头,但它不起作用: $file = FileGetShortName("C:\Users\PHSD100-SIC\Deskto
所以我试图向自己发送数据并接收数据然后打印它,现在我已经测试了一段时间,我注意到它没有发送任何东西,事实上,也许它是,但我没有正确接收它,我需要这方面的帮助。 这就是我用来发送数据的
问题:开发人员创建自己的序列化格式有多常见?具体来说,我使用 java 本质上将对象作为一个巨大的字符串发送,并用标记来分隔变量。 我的逻辑:我选择这个是因为它几乎消除了语言依赖性(忽略java的修改
我必须在 Linux 上编写一个应用程序,该应用程序需要与具有自定义以太网类型的设备进行通信。甚至在如何编写这样的应用程序中也有很多解决方案。一个缺点是需要 root 访问权限(AFAIK)。之后释放
我有一个包含三个单选按钮选项的表单。我需要将表单数据提交到另一个文件,但由于某种原因,发送的数据包含所选单选按钮的值“on”,而不是 value 属性的值。 我尝试通过 post() 函数手动操作和发
基本上我想实现这样的目标: Process 1 Thread 1 Receive X from process 2 Thread 2 Receive Y from proces
我目前正在 Google App Engine 上开发一个系统,对它还很陌生,我正在使用 Java 平台进行开发。我在 servlet 之间发送 session 对象时遇到问题。我已经在 appeng
当我尝试将“this”(触发的元素)作为参数发送给函数时,函数收到“Object[Document build.php]”作为参数,而不是触发的元素。请让我知道我的错误: function set(a
我正在寻找让我的应用响应联系人 > 发送的魔法咒语。我希望能够接收联系人的 URI 以便检索联系人。谁有 list 过滤器/代码 fragment 吗? 最佳答案 我没有睾丸,但您可以尝试基于 ACT
关于我心爱的套接字的另一个问题。我先解释一下我的情况。之后我会告诉你是什么困扰着我。 我有一个客户端和一个服务器。这两个应用程序都是用 C++ 编写的,实现了 winsock2。连接通过 TCP 和
我看到了这篇文章 http://www.eskimo.com/~scs/cclass/int/sx5.html 但这部分让我感到困惑:如果我们已经使用 send_array 或 send_array_
我对这行代码有疑问。我必须将一个数据包带到一个端口并重新发送到接口(interface)(例如:eth0)。我的程序成功地从端口获取数据包,但是当我重新发送(使用 send())到接口(interfa
我正在尝试编写一个 X11 输入驱动程序,它可以使用我的 Android 手机上的触摸屏来移动和单击鼠标。我可以正常移动鼠标,但我无法让应用程序正确识别点击。我当前的代码位于 https://gist
我是一名优秀的程序员,十分优秀!