Not logged in. · Lost password · Register
Forum: MatriX RSS
Avatar
sunkas85 #1
Member since Aug 2012 · 6 posts
Group memberships: Members
Show profile · Link to this post
Subject: Facebook C# Mono help
Hi

I am trying to create a facebook client chat with Monotouch/Unity C# and xmpp mono edition. I am extremely new to xmpp so could use some help. Here is my code so far:

    void setup () {
        this.xmppClient     = new XmppClient()
            {
                Password = "myfbpassword",
                Username = "xxxx@gmail.com", //have also tried my "username"
                XmppDomain = "chat.facebook.com", //just took a guess here
                Status = "Online",
                Show = Show.chat,
                Port = 5222,
                StartTls = true,
                Hostname = "chat.facebook.com",
            };

            // Event handlers for Matrix
            this.xmppClient.OnBeforeSasl += this.xmppClient_OnBeforeSasl;
            this.xmppClient.OnLogin += this.xmppClient_OnLogin;
            this.xmppClient.OnAuthError += this.xmppClient_OnAuthError;
            this.xmppClient.OnError += this.xmppClient_OnError;

            this.xmppClient.OnRosterStart += this.xmppClient_OnRosterStart;
            this.xmppClient.OnRosterItem += this.xmppClient_OnRosterItem;
            this.xmppClient.OnRosterEnd += this.xmppClient_OnRosterEnd;
            this.xmppClient.OnReceiveXml += this.xmppClient_OnReceiveXml;
            this.xmppClient.OnSendXml += this.xmppClient_OnSendXml;
        
            try
            {
        Debug.Log ("Before Open");
                this.xmppClient.Open();
        Debug.Log ("After Open");
            }
            catch (Exception ex)
            {
                Debug.Log("During the open");
                Console.WriteLine(ex.Message);
            }

            //Thread.Sleep(500*60);

            this.xmppClient.SendPresence(Show.chat, "Online");

            // Get Online users
            this.xmppClient.OnPresence += this.xmppClient_OnPresence;
            this.xmppClient.AutoRoster = true;
    Debug.Log("OK So far");
    }
   
     public void xmppClient_OnBeforeSasl(object sender, Matrix.Xmpp.Sasl.SaslEventArgs e) // Never gets called :(
        {
            Debug.Log("OnBeforeSasl");
            e.Auto = false;
            e.SaslMechanism = Matrix.Xmpp.Sasl.SaslMechanism.X_FACEBOOK_PLATFORM;
   
            e.SaslProperties = new Matrix.Xmpp.Sasl.Processor.Facebook.FacebookProperties
                                   {
                                       ApiKey = API_KEY,
                                       ApiSecret = API_SECRET,
                                       AccessToken = "109552852527127|CIiQ_Uh0wKWkzDXn7I3S2_jQZKU" //hardcoded for the time being
                                   };
            Console.WriteLine(e.SaslProperties);
        }

        private void xmppClient_OnSendXml(object sender, TextEventArgs e)
        {
            Debug.Log("xmppClient_OnSendXml = "+ e.Text +"_end_");
        }

        private void xmppClient_OnError(object sender, ExceptionEventArgs e)
        {
            Debug.Log("OnError = "+e.Exception.Message);
        }

I have hardcoded the Accesstoken until our facebook integration is done. Got it from the https://graph.facebook.com/oauth/access_to…?grant_type=c… url. The result from this code is:

Before Open

After Open

xmppClient_OnSendXml = <presence xmlns="jabber:client">
  <show>chat</show>
  <status>Online</status>
  <priority>0</priority>
</presence>_end_

OnError = Connection request failed.

OnError = Object reference not set to an instance of an object

OK So far

xmppClient_OnSendXml = <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" to="chat.facebook.com" version="1.0" >_end_

xmppClient_OnBeforeSasl or no other delegate methods are called.

The facebook app has also been set to have the extended permission of "xmpp_login". Any ideas are much appreciated!

Best Regards
Jonas Andersson
Avatar
Alex #2
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
What you don't need is username and password when you use the X-Facebook-Platform auth, but this should not matter.

Please remove also this line:
this.xmppClient.SendPresence(Show.chat, "Online");

MatriX send the presence automatically to your server.
The Open Method is asynchronous.  After the Open call MatriX just started to connect, authenticate and much more. Dob't execute and code like SendPresence until you session is authenticated and ready to use. You session is normally ready when you get the first incoming OnPresence handler.

If it still does not work please post the complete xml log if there any.

We have never tested the regular Mono build with Unity for Monotouch.

Alex
Avatar
sunkas85 #3
Member since Aug 2012 · 6 posts
Group memberships: Members
Show profile · Link to this post
Thanks for your reply! I removed the suggested line and got this output:

xmppClient_OnSendXml = <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" to="chat.facebook.com" version="1.0" >_end_

OnReveiveXml = <stream:stream xmlns:stream="http://etherx.jabber.org/streams" id="FA7BED70" from="chat.facebook.com" version="1.0" xmlns="jabber:client" xml:lang="en" >_end_

OnReveiveXml = <stream:features xmlns:stream="http://etherx.jabber.org/streams">
  <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls" />
  <mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
    <mechanism>X-FACEBOOK-PLATFORM</mechanism>
    <mechanism>DIGEST-MD5</mechanism>
  </mechanisms>
</stream:features>_end_

xmppClient_OnSendXml = <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls" />_end_

OnReveiveXml = <proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls" />_end_

xmppClient_OnSendXml = <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" to="chat.facebook.com" version="1.0" >_end_

OnReveiveXml = <stream:stream xmlns:stream="http://etherx.jabber.org/streams" id="0A97BB7A" from="chat.facebook.com" version="1.0" xmlns="jabber:client" lang="en" >_end_

OnReveiveXml = <stream:features xmlns:stream="http://etherx.jabber.org/streams">
  <mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
    <mechanism>X-FACEBOOK-PLATFORM</mechanism>
    <mechanism>DIGEST-MD5</mechanism>
  </mechanisms>
</stream:features>_end_

OnBeforeSasl

xmppClient_OnSendXml = <auth mechanism="X-FACEBOOK-PLATFORM" xmlns="urn:ietf:params:xml:ns:xmpp-sasl" />_end_

OnReveiveXml = <challenge xmlns="urn:ietf:params:xml:ns:xmpp-sasl">dmVyc2lvbj0xJm1ldGhvZD1hdXRoLnhtcHBfbG9naW4mbm9uY2U9OTdGODIzRkM0Njk2NEM2NTBBMkE0RUVDRDM1MjY4NTk=</challenge>_end_

xmppClient_OnSendXml = <response xmlns="urn:ietf:params:xml:ns:xmpp-sasl">bWV0aG9kPWF1dGgueG1wcF9sb2dpbiZhcGlfa2V5PTEwOTU1Mjg1MjUyNzEyNyZhY2Nlc3NfdG9rZW49MTA5NTUyODUyNTI3MTI3JTdDQ0lpUV9VaDB3S1drekRYbjdJM1MyX2pRWktVJnY9MS4wJmNhbGxfaWQ9Mzc3OTAxMzkwJm5vbmNlPTk3RjgyM0ZDNDY5NjRDNjUwQTJBNEVFQ0QzNTI2ODU5</response>_end_

OnReveiveXml = <failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
  <not-authorized />
</failure>_end_

OnAuthError

xmppClient_OnSendXml = </stream:stream>_end_

OnReveiveXml = </stream:stream>_end_

Entered my facebook email and password. Are they not needed?

Jonas
This post was edited on 2012-08-20, 10:00 by sunkas85.
Avatar
Alex #4
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
In reply to post #1
Quote by sunkas85 on 2012-08-17, 16:48:
The facebook app has also been set to have the extended permission of "xmpp_login". Any ideas are much appreciated!

no you don't need them. The server returns an authentication error. Something is wrong with your token or your Facebook app.
Have you checked out these docs?
http://www.ag-software.net/matrix-xmpp-sdk/matrix-develope… ?

Do you you request the xmpp_login permission?

Alex
Avatar
sunkas85 #5
Member since Aug 2012 · 6 posts
Group memberships: Members
Show profile · Link to this post
I have set the xmpp_login permission on the facebook app settings (on developer.facebook.com). Do you need to specify them when you request the token? Can you give me any pointers to how to do that?

The only thing I found on developer.facebook.com was this url (https://graph.facebook.com/oauth/access_to…?grant_type=c…) but it does not allow for any setting of permissions...

Jonas
Avatar
Alex #6
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
I have never worked with Facebook graph. We always used .NET APIs where you can pass the permissions when you request the token.
Does the login page show and request the XMPP permission?

See also: https://developers.facebook.com/docs/opengraph/authenticat…

Alex
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: MatriX RSS