XFacebookPlatform.as no longer connects to Facebook

Facebook says starting today, Oct 1st, we need to drop the session_key and sig params and add the access_token.

I made the changes to XFacebookPlatform.as as Facebook suggested:

var challengeResponse:String = "access_token=" + fb_access_token;
challengeResponse += "&api_key=" + responseMap.api_key;
challengeResponse += "&call_id=" + responseMap.call_id;
challengeResponse += "&method=" + responseMap.method;
challengeResponse += "&nonce=" + responseMap.nonce;
//challengeResponse += "&session_key=" + responseMap.session_key;
//challengeResponse += "&sig=" + responseMap.sig;
challengeResponse += "&v=" + responseMap.v;


However I keep getting not-authorized failures no matter what I try. My access_token comes from the actionscript-facebook-api - it appears to be correct.

Does anyone have a working example?

I figured it out. The changes above are correct, but I also had to change:

protected var _tls:Boolean = true; // was set to false

in XMPPTLSConnection.as. TLS is required but I don’t think Facebook is marking it off as required in the stream. Setting it manually did the job.

Mark,

I filed a bug (in the form of a new discussion to ask for the changes you’ve made). http://community.igniterealtime.org/message/218659#218659

I am trying to use the XFacebookPlatform and have not been able to connect as of yet. Since you have had success, is it possible to post a snippet of your code for those of us who are struggling? I have been trying for hours to no avail. All the sample code I’ve found is prior to these changes so I am not sure what I need to do differently, but it’s not working. I’m getting authorization errors.

(Note: I have updated my XIFF code with your suggested changes)

Here is my code:

public function testChat ():void{

// var jid:EscapedJID = new EscapedJID("-"+fbUserid+ "@chat.facebook.com");

var connection:XMPPConnection = new XMPPConnection();

connection.addEventListener(LoginEvent.LOGIN, onXIFFLogin);

connection.addEventListener(XIFFErrorEvent.XIFF_ERROR, onXIFFError);

connection.addEventListener(IncomingDataEvent.INCOMING_DATA, onXIFFIncomingData);

connection.addEventListener(MessageEvent.MESSAGE, onXIFFMessage);

connection.server = ‘chat.facebook.com’;

connection.port = 5222;

// connection.username = username;

XFacebookPlatform.fb_api_key = “***********************”;

XFacebookPlatform.fb_secret = “***************************”;

XFacebookPlatform.fb_access_token = “***********************”;

var fb_auth:XFacebookPlatform = new XFacebookPlatform(connection);

var result:Boolean = connection.connect(0);

}

Any help would be much appreciated.

Cheers.

Hi Laurie,

It looks like you are hard coding your access token. You need to get the new encrypted access token. I do this from the facebook-actionscript-api by signing into my FB app, then calling :

ar:FacebookAuthResponse = Facebook.getAuthResponse();


ar.accessToken is what you use as fb_access_token in the challenge response code I posted above.

Sorry I can’t post all my code, but this fix and my fixes above cover everything (unless something ELSE changed recently!). I haven’t worked with this in a few months now.

GL,

Mark Z

Thanks for your quick response. I do get the Access token in earlier code not shown here, but when I edited out my key info for the post, I did unfortunately give the impression it was hardcoded.

Oh ok. The next thing I would do then is take a look at the XIFF sample app. It uses some class called com.yourpalmark.ChatManager (don’t have the exact names) which makes the connection. It sets things up properly and I remember using that in my code. I had to pass the new encrypted access token through it.

Awesome, I do have that ChatManager code in my sights and it helps to know that that is how you made yours work. Thanks!

Sorry for the late response.

I have updated XIFF and XIFFGUI (included in the examples directory of XIFF on SVN) to work with the latest Facebook changes. (Thanks to Mark Zamoyta for catching this originally).

Facebook has officially pulled support for the prior version as of December 8th, so all XIFF users connecting to Facebook will need to update.

Thanks.

There was one thing that wasnt mentioned, that I had to have in order to get the chat working again…

  1. Use XMPPTLSConnection instead of XMPPConnection

connection = new XMPPTLSConnection();

  1. set tls = true on the XMPPTLSConnection object

connection.tls = true;

  1. Set the app id and access token from Facebook.getAuthResponse()

XFacebookPlatform.fb_app_id = applicationId;

XFacebookPlatform.fb_access_token = Facebook.getAuthResponse().accessToken;

**4) Set the username property to the uid from the auth response **

connection.username = Facebook.getAuthResponse().uid;

Hope this helps anyone else who might be running into similar problems.

Hi Zo,

I tried your code and still could not make the chat log in. Here is an example of my code:

private function goOnline():void

{

if (!connection) connection = new XMPPTLSConnection();

connection.tls = true;

connection.useAnonymousLogin = false;

connection.username = Facebook.getAuthResponse().uid;

connection.server = “chat.facebook.com”;

connection.port = 5222;

connection.addEventListener(LoginEvent.LOGIN, onLogin);

connection.addEventListener(XIFFErrorEvent.XIFF_ERROR, onError);

connection.addEventListener(IncomingDataEvent.INCOMING_DATA, onIncomingData);

connection.addEventListener(MessageEvent.MESSAGE, onMessage);

connection.addEventListener(PresenceEvent.PRESENCE, onPresence);

connection.addEventListener(ConnectionSuccessEvent.CONNECT_SUCCESS, onConnectionSuccess);

if (Facebook.getAuthResponse()) //, for 1.8.1 fb api

{

var api_key:String;

var access_token:String = Facebook.getAuthResponse().accessToken//fbSession.sessionKey;

// having the secret key here is a big security issue that must be fixed somehow

if (FlexGlobals.topLevelApplication.parameters.UICServer)

{

api_key = “uic api key”;

}else

{

api_key = “clients api key”;

}

XFacebookPlatform.setFacebookParams(api_key, access_token); // this a custom function i made to set the paramaters

connection.connect(0);

}

The IncomingDataEvent and ConnectionSuccessEvent are caught. The LoginEvent is not though. So apparently it does not log in in the facebook chat (i think). I have updated to the latest XIFF version as well.

Is there something wrong with the code? Am I missing anything?

Thank you in advance for your help

Regards

Hi Manos,

The user will need to athenticate with Facebook before you connect them to chat.

There are many ways you can log a user into your site using facebook. You could use the PHP SDK, the javascript API, or the flash GraphAPI libray, or a different FB SDK of your choice.

Hi Zo,

Thanks for your quick reply. The user is allready logged in. The app does that when it starts. That part works fine. Is there anything else I am missing?

Thanks

Are you requesting the FacebookExtendedPermission.XMPP_LOGIN permission from the user?

Yes, I do that when the user loggins. I send it in the permissions array. Do I also have to do it before trying to connect to the chat? And if yes, how?

Thanks again!!!

Hey Manos,

Have you looked at the svn code and run the provided XIFFGUI example?

It includes a working example of connecting to Facebook Chat.

Hope that helps!

Mark

Hi Mark,

I tried to run the XIFFGUI example, but I can not make it work. I can’t even make the facebook to initiate. I am trying to run the example from a server. Any ideas?

Thanks,

Manos

I think I got it working. My code looks like this now (i moved the listeners to a seperate function):

private function goOnline():void

{

XMPPConnection.registerSASLMechanism( “DIGEST-MD5”, XFacebookPlatform );

keepAlive = new Timer(2 * 60 * 1000);

keepAlive.addEventListener(TimerEvent.TIMER, onKeepAliveLoop);

if (Facebook.getAuthResponse()) //, for 1.8.1 fb api

{

var api_key:String = “My FB api key” ;

var access_token:String = Facebook.getAuthResponse().accessToken;

XFacebookPlatform.fb_access_token = access_token;

XFacebookPlatform.fb_app_id = api_key;

connection.domain = “chat.facebook.com”;

connection.tls = true;

connection.username = Facebook.getAuthResponse().uid;

connection.server = “chat.facebook.com”;

connection.port = 5222;

connection.connect(0);

}

}

I was using a different version of as3crypto library, that’s why it was not completing the handshake with the server. Thus, could not log in.

Thank you for your help!!!

Regards,

Manos