Not logged in. · Lost password · Register
Forum: agsXMPP RSS
C#
Avatar
pisey #1
Member since Sep 2012 · 13 posts
Group memberships: Members
Show profile · Link to this post
Subject: Connecting to Facebook Chat using X-FACEBOOK-PLATFORM with agsxmpp
how to Connecting to Facebook Chat using X-FACEBOOK-PLATFORM with agsxmpp?
Avatar
Alex #2
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
1) make sure you run the latest code from SVN
2) X-FACEBOOK-PLATFORM authentication works similar to MatriX which is described here: http://www.ag-software.net/matrix-xmpp-sdk/matrix-develope…

Alex
Avatar
pisey #3
Member since Sep 2012 · 13 posts
Group memberships: Members
Show profile · Link to this post
I use this code, but it does not work

  1. public MainWindow()
  2. {
  3.     InitializeComponent();
  4.     xmppCon.Server = "chat.facebook.com";
  5.     xmppCon.Port = 5222;
  6.     xmppCon.OnSaslStart+=new agsXMPP.Sasl.SaslEventHandler(xmppCon_OnSaslStart);
  7.     xmppCon.OnLogin+=new ObjectHandler(xmppCon_OnLogin);
  8. }
  9. private void xmppCon_OnSaslStart(object sender, SaslEventArgs args)
  10. {
  11.     args.Auto=false;
  12.     args.Mechanism = agsXMPP.protocol.sasl.Mechanism.GetMechanismName(agsXMPP.protocol.sasl.MechanismType.X_FACEBOOK_PLATFORM);
  13.     args.ExtentedData = new FacebookExtendedData
  14.                     {
  15. AccessToken = "AAADz8ZB4OzZBwBAEa1LBHyedy0I2BNlsLkimktJC5QHrAWut1ParwDgCc4HqEBDo33mgo7ETJy0mpKzRcQ9kGchnFnSPxig76wdqxpTcmanABJ32ul",
  16. ApiKey = "268228996550636" };
  17.  
  18.                         }
  19. private void xmppCon_OnLogin(object sender)
  20. {
  21.     if (xmppCon.Authenticated == false)
  22.     {
  23.         MessageBox.Show("Not Authenticated!");
  24.     }
  25.     else
  26.     {
  27.         Presence p = new Presence(ShowType.chat, "Online");
  28.         p.Type = PresenceType.available;
  29.         xmppCon.Send(p);
  30.     }   
  31. }
This post was edited on 2013-04-28, 20:58 by Alex.
Avatar
Alex #4
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Code looks fine, please post your debug xml. Do you request the XMPP permission with your Facebook API when getting the token?
This post was edited on 2013-01-30, 08:58 by Alex.
Avatar
davidroyale #5
Member since Oct 2013 · 6 posts
Group memberships: Members
Show profile · Link to this post
Hi,
i got it working now. Permissions and token were fine. I replaced the following line in agsXMPP.Sasl.Facebook.FacebookMechanism:

  1. XmppClientConnection.Send(new Response(ToB64String(res)));

with this:
  1. XmppClientConnection.Send(new Response(res));


Thanks for your support and great product.

Danke aus dem Ruhrgebiet ;)
This post was edited 2 times, last on 2013-10-24, 15:16 by Alex.
Avatar
Alex #6
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
ups, ya you are right. We encoded the reply twice to base64.
This code was backported from MatriX to agsXMPP and untested. The Sasl API is quite different in MatriX.

Thanks for finding this problem. I'll upload new code and a new binary.

Strange that many people requested this feature and then never complained that its broken while it was there ;-)
Avatar
davidroyale #7
Member since Oct 2013 · 6 posts
Group memberships: Members
Show profile · Link to this post
(Sorry for posting in the wrong thread)

Maybe im the first one using this feature - Glad to help improving your product in my lunchbreak :-D
Avatar
Alex #8
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
appreciate your help, thanks again.
new binary is uploaded and code is committed to SVN.
Avatar
tdean #9
Member since Feb 2014 · 3 posts
Group memberships: Members
Show profile · Link to this post
Subject: Following along
I have been following along with this thread and it has been very helpful.  I am just creating a simple web application that will send a chat message from one facebook user to another.  I am not sure I understand on how to extract some information that I would need to send the message such as the person the message is from.  Here is what I have so far:

  1.         public void SendFacebookMessage()
  2.         {
  3.             //This returns a list<string> of facebook id's
  4.             FacebookFriendIds = GetFacebookFriends(new List<string> { "friend1", "friend2" });
  5.  
  6.             var auth = new agsXMPP.protocol.sasl.Auth();
  7.             auth.Attributes.Add("mechanism", "X_FACEBOOK_PLATFORM");
  8.             auth.Value = (String)Session["FacebookContext"]; //this is the accesstoken returned from the user logging in
  9.  
  10.            
  11.             xmpp.OnSaslStart += delegate(object sender, agsXMPP.Sasl.SaslEventArgs args)
  12.             {
  13.                 var facebookKey = ConfigurationManager.AppSettings["FacebookKey"];
  14.                 var facebookSecret = ConfigurationManager.AppSettings["FacebookSecret"];
  15.  
  16.                 args.Auto = false;
  17.                 agsXMPP.protocol.sasl.Mechanism.GetMechanismName(agsXMPP.protocol.sasl.MechanismType.X_FACEBOOK_PLATFORM);
  18.  
  19.                 //how does this get used?
  20.                 args.ExtentedData = new FacebookExtendedData
  21.                 {
  22.                     ApiKey = facebookKey,
  23.                     AccessToken = (String)Session["FacebookContext"]
  24.                 };
  25.  
  26.                 xmpp.Send(auth);
  27.             };
  28.  
  29.             xmpp.OnLogin += delegate(object sender)
  30.             {
  31.                 //Session data and property values have been cleared once call is returned here
  32.                 string senderId = string.Format("-{0}@chat.facebook.com", FacebookId);
  33.  
  34.                 foreach (string id in FacebookFriendIds)
  35.                 {
  36.                     string recieverId = string.Format("-{0}@chat.facebook.com", id);
  37.                     xmpp.Send(new agsXMPP.protocol.client.Message(new Jid(recieverId), new Jid(senderId), agsXMPP.protocol.client.MessageType.chat, MessageContent));
  38.                 }
  39.  
  40.             };
  41.                
  42.         }

What is the benefit of populating the args.ExtendedData and how does it get used?  I have stored some information in session but once the conneciton is made and OnLogin is called, the session is empty.

Can anyone help clear up some of the questions I have?
This post was edited on 2014-02-12, 20:56 by Alex.
Avatar
Alex #10
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
see the post above from pisey. He posted all code you need to connect with the X_FACEBOOK_PLATFORM SASL mechanism.
And make sure that you use the latest build or SVN code. I the latest code there was a bug fixed regarding the X_FACEBOOK_PLATFORM Sasl implementation in agsXMPP.

Alex
Avatar
tdean #11
Member since Feb 2014 · 3 posts
Group memberships: Members
Show profile · Link to this post
Thanks Alex.

I think everything is working now except I need to understand how to pass data to the event handlers.  Once the user has authenticated through facebook and is returned to the site, I am capturing their authentication token and storing it in session which I was planning on using in the OnSasl_Start and OnLogin events but the session is empty when it gets to those events.

  1. void xmppClient_OnSaslStart(object sender, agsXMPP.Sasl.SaslEventArgs args)
  2. {
  3.     log.Debug("xmppClient_OnSaslStart");
  4.  
  5.     var facebookKey = ConfigurationManager.AppSettings["FacebookKey"];
  6.  
  7.  
  8.     args.Auto = false;
  9.     args.Mechanism =     agsXMPP.protocol.sasl.Mechanism.GetMechanismName(agsXMPP.protocol.sasl.MechanismType.X_FACEBOOK_PLATFORM);
  10.     args.ExtentedData = new FacebookExtendedData
  11.     {
  12.        
  13.         ApiKey = facebookKey,
  14.         AccessToken = (String)Session["FacebookContext"]
  15.     };
  16. }
  17.  
  18. void xmppClient_OnLogin(object sender)
  19. {
  20.     log.Debug("xmppClient_OnLogin");
  21.  
  22.     FacebookFriendIds = GetFacebookFriends(new List<string> { "Friend1", "Friend2" });
  23.  
  24.     var senderId = string.Format("-{0}@chat.facebook.com", FacebookId);
  25.  
  26.     foreach (string id in FacebookFriendIds)
  27.     {
  28.         var recieverId = string.Format("-{0}@chat.facebook.com", id);
  29.         xmppClient.Send(new agsXMPP.protocol.client.Message(new agsXMPP.Jid(recieverId), new agsXMPP.Jid(senderId), agsXMPP.protocol.client.MessageType.chat, MessageContent));
  30.     }
  31. }

Any idea how I can pass this session data to the events?
This post was edited on 2014-02-19, 09:54 by Alex.
Avatar
Alex #12
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
your last questions is more related to web development than to XMPP.

As long as you don't have a token there is no need to setup the XMPP connection. You could setup it after you retrieved your token and then of course pass it to the event at the same time with a lambda expression.
But this all depends of the architecture of your web application. A common solution is to put the whole Xmpp connection in the session as well.

Alex
Avatar
tdean #13
Member since Feb 2014 · 3 posts
Group memberships: Members
Show profile · Link to this post
Thanks Alex, you're right I know it's more of a web development question I just figured that someone would have encountered a similar scenario and would have some suggestions. 

I was able to accomplish what I needed by using lambda expression as you suggested, thank you very much for pointing me in the right direction.
This post was edited on 2014-02-19, 22:12 by tdean.
Avatar
Alex #14
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
sorry too late, but here is an example of passing the token to the event during initialization with a lambda;

  1. XmppCon = new XmppClientConnection();
  2.  
  3. XmppCon.OnSaslStart += (sender, args) =>
  4. {
  5.     args.Auto = false;
  6.     args.Mechanism = MechanismType.X_FACEBOOK_PLATFORM);
  7.     args.ExtentedData = new FacebookExtendedData
  8.     {
  9.  
  10.         ApiKey = "your_facebook_key",
  11.         AccessToken = "your_access token"
  12.     };
  13. };
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: agsXMPP RSS