0
votes

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.

2
I stuck up with this same issue. Did you find any working solution?KishoreK

2 Answers

0
votes

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]
0
votes

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.