Facebook聊天困难用户的JID

我有一个连接到Facebook的XMPP使用聊天API的问题。 实际上唯一的问题是我不知道JID,有时候用户没有提供他的用户名,并且不能简单地通过将他/她的用户ID设置为JID来工作。

我已经尝试从我使用的iChat的Facebook我自己的JID,它完美的工作。

所以,根据文档,我宁愿使用访问令牌而不是用户名/密码login用户聊天。

我已成功login,访问令牌的forms为:18112 … | f6daa87 …- 1392 … | qE7 …- sD6 …

现在我用Eric Chamberlain的XMPPStreamFacebook使用XMPPFramework。 这是我开始聊天的方法

-(void)launchService { if (xmppStream) { [xmppStream release]; xmppStream = nil; } xmppStream = [[XMPPStreamFacebook alloc] init]; xmpReconnect = [[XMPPReconnect alloc] initWithStream:xmppStream]; if (xmppRosterStorage) { [xmppRosterStorage release]; xmppRosterStorage = nil; } xmppRosterStorage = [[XMPPRosterCoreDataStorage alloc] init]; if (xmppRoster) { [xmppRoster release]; xmppRoster = nil; } xmppRoster = [[XMPPRoster alloc] initWithStream:xmppStream rosterStorage:xmppRosterStorage]; [xmppStream addDelegate:self]; [xmppRoster addDelegate:self]; [xmppRoster setAutoRoster:YES]; [xmppStream setHostName:@"chat.facebook.com"]; [xmppStream setHostPort:5222]; [xmppStream setMyJID:[XMPPJID jidWithString:@"test@chat.facebook.com"]]; // You may need to alter these settings depending on the server you're connecting to allowSelfSignedCertificates = NO; allowSSLHostNameMismatch = NO; // Uncomment me when the proper information has been entered above. NSError *error = nil; if (![xmppStream connect:&error]) NSLog(@"Error connecting: %@", error); } 

  - (void)xmppStreamDidConnect:(XMPPStream *)sender { NSError *error = nil; // [xmppStream authenticateWithAccessToken:[self appDelegate].token error:&error]; NSLog(@"---------- xmppStreamDidConnect: ----------"); isOpen = YES; if (![[self xmppStream] authenticateWithAccessToken:[self appDelegate].token error:&error]) { NSLog(@"Error authenticating: %@", error); } } - (void)xmppStream:(XMPPStream *)sender didNotAuthenticate:(NSXMLElement *)error { NSLog(@"---------- xmppStream:didNotAuthenticate: ---------- %@ desc %@",error,[error description]); } ... 

在控制台中,我得到:

 2011-01-15 19:41:06.547 Facebookwebsiteziosfbconnect[81160:207] SEND: <?xml version='1.0'?> 2011-01-15 19:41:06.548 Facebookwebsiteziosfbconnect[81160:207] SEND: <stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' to='chat.facebook.com'> 2011-01-15 19:41:06.920 Facebookwebsiteziosfbconnect[81160:207] RECV: <?xml version="1.0"?><stream:stream id="4788E768" from="chat.facebook.com" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0" xml:lang="en"> 2011-01-15 19:41:06.922 Facebookwebsiteziosfbconnect[81160:207] RECV: <stream:features><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>X-FACEBOOK-PLATFORM</mechanism><mechanism>DIGEST-MD5</mechanism></mechanisms></stream:features> 2011-01-15 19:41:06.922 Facebookwebsiteziosfbconnect[81160:207] ---------- xmppStreamDidConnect: ---------- 2011-01-15 19:41:07.829 Facebookwebsiteziosfbconnect[81160:207] ---------- xmppStream:didNotAuthenticate: ---------- (null) desc (null) 

我只是想确认,如果我提供了真正的login(我在iChat中使用)而不是test@chat.facebook.com,并且我的密码身份validation在didConnect身份validation工作。

有没有人看到这个问题? Thx提前。

首先获取使用iPhone SDK的login用户的UID,然后使用此用户名而不是用户名作为JID。

 FBUID@chat.facebook.com instead of username@chat.facebook.com 

我相信你可以使用FB聊天第三方客户端的唯一方法是如果用户已经创build了一个FB用户ID。

另外,只要确保XMPP身份validation之后,您应该从服务器接收完整的JID。 像这样的东西

 <iq id="0" type="result"> <bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"> <jid>example@domain.com/resource</jid> </bind> </iq> 

那就是你使用的JID。