Facebook聊天困难用户的JID

时间:2011-01-15 18:45:13

标签: facebook ios chat xmpp

我在连接Facebook的XMPP时遇到问题,无法使用聊天API。实际上唯一的问题是我不知道JID,有时候用户没有提供他的用户名,只是将他/她的userID设置为JID就无法工作。

我在Facebook上尝试过自己的JID,我在iChat中使用它并且效果很好。

因此,根据文档,我应该使用访问令牌而不是用户名/密码将用户登录到聊天中。

我已成功登录,访问令牌的格式如下: 18112 ... | f6daa87 ...- 1392 ... | qE7 ...- SD6 ...

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

-(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)

我只是想确认一下,如果我提供真实登录(我在iChat中使用)而不是test@chat.facebook.com,并且我在didConnect中进行了密码验证,那么验证就可以正常工作。

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

2 个答案:

答案 0 :(得分:0)

首先使用Facebook SDK for iphone获取登录用户的uid,然后使用此uid代替用户名作为JID。

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

答案 1 :(得分:0)

我认为使用FB聊天的第三方客户端的唯一方法是用户是否创建了FB用户ID。

此外,为了确保您的XMPP身份验证后,您应该从服务器收到完整的JID。像这样的东西

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

这是您使用的JID。

相关问题