好吧,我可能会做些傻事,但过去几个小时我一直在用头撞墙,到目前为止我不知道我做错了什么。
目前我正在尝试与PLAIN SASL合作,因为Facebook似乎积极使OAuth2成为非Web应用程序的痛苦,但只要我能让它工作,它对我来说真的没有任何影响不知。
当前代码:
_client = new Client(JID(username /* no @chat.facebook.com */), password);
_client->setServer("chat.facebook.com");
_client->setPort(5222);
_client->setSASLMechanisms(gloox::SaslMechPlain);
_client->setTls(gloox::TLSPolicy::TLSRequired);
_client->connect(false);
_client->login(); // not necessary?
QThread::sleep(10); // arbitrary sleep; should be sufficient
std::cout << _client->authed() << std::endl; // false
std::cout << _client->authError() << std::endl; // AuthErrorUndefined
_client->rosterManager()->fill();
// neither one has any effect
MessageSession(_client, JID("friend@chat.facebook.com")).send("balls");
MessageSession(_client, JID("friend")).send("balls");
std::cout << _client->rosterManager()->roster()->size() << std::endl; // 0
编辑:就此而言,我无法让Gloox使用Gmail(没有尝试任何其他XMPP服务器)。
答案 0 :(得分:1)
username@chat.facebook.com
,而不仅仅是username
- 这对SASL身份验证非常重要,它不适用于错误的JID。<stream:features>...</stream:features>
数据包中看到支持的SASL机制答案 1 :(得分:0)
好吧,我还不能100%确定Gloox的问题是什么,但以下大致相同的Swiften代码没有问题。
SimpleEventLoop* eventLoop = new SimpleEventLoop();
BoostNetworkFactories networkFactories(eventLoop);
_client = new Client
(
username.append("@chat.facebook.com").toStdString(),
password.toStdString(),
&networkFactories
);
_client->setAlwaysTrustCertificates();
_client->onConnected.connect([&] () { signInStatus = SignInStatus::Success; });
_client->onDisconnected.connect([&] (const boost::optional<ClientError>& e) {
signInStatus = SignInStatus::InvalidCredentials;
});
_client->connect();
std::thread([&] () { eventLoop->run(); }).detach();
while (signInStatus == SignInStatus::NotSignedIn)
{
QThread::sleep(1);
}
if (signInStatus == SignInStatus::InvalidCredentials)
{
return signInStatus;
}
_client->requestRoster();
QThread::sleep(5);
std::cout << _client->getRoster()->getItems()[0].getName() << std::endl;
Message::ref message(new Message());
message->setTo(_client->getRoster()->getItems()[0].getJID());
message->setFrom(JID());
message->setBody("balls");
_client->sendMessage(message);