Facebook Chat 难度用户的 JID

发布于 2024-10-12 18:40:44 字数 3781 浏览 1 评论 0原文

我在连接 Facebook 的 XMPP 以使用聊天 api 时遇到问题。事实上,唯一的问题是我不知道 JID,有时用户没有提供他的用户名,并且仅仅将他/她的 userID 设置为 JID 是行不通的。

我已经在 iChat 中使用了来自 facebook 的自己的 JID,效果非常好。

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

我已成功登录,访问令牌的格式为: 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:@"[email protected]"]];

    // 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 中使用)而不是 [email protected],以及我在 didConnect 中的密码身份验证一切都有效。

有人看到问题所在吗? 提前谢谢。

I've a problem connecting to Facebook's XMPP to use chat api. In fact the only problem is that I don't know the JID, sometime user doesn't have provided his username and it won't work simply by settings his/her userID as an JID.

I've tried my own JID from facebook that I use in iChat and it worked perfectly.

So, according to the docs I should rather log user to the chat by using access token instead of username/password.

I'm successfuly logged in, the accesss token is in the form:
18112...|f6daa87...-1392...|qE7...-sD6...

Now I use the XMPPFramework with XMPPStreamFacebook by Eric Chamberlain.
This is my method starting the chat

-(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:@"[email protected]"]];

    // 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);  
}

and

   - (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]);
}
...

In the console I get:

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)

I just want to confirm that if I provided the real login (that I use in iChat) instead of [email protected], and my password authentication in didConnect everything the authentication works.

Does anyone see the problem?
Thx in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

Spring初心 2024-10-19 18:40:44

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

[email protected] instead of [email protected]

First of all get the uid of the logged in user using the Facebook SDK for iphone and then use this uid instead of username as JID.

[email protected] instead of [email protected]
马蹄踏│碎落叶 2024-10-19 18:40:44

我相信您可以使用第三方客户端进行 FB 聊天的唯一方法是用户创建了 FB 用户 ID。

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

<iq id="0" type="result">
  <bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">
    <jid>[email protected]/resource</jid>
  </bind>
</iq>

就是你使用的JID。

I believe the only way you can use a 3rd party client with FB chat is if the user has created a FB user id.

In addition, just to be sure, after your XMPP authentication you should receive the full JID from the server. something like this

<iq id="0" type="result">
  <bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">
    <jid>[email protected]/resource</jid>
  </bind>
</iq>

that is the JID you use.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文