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:
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:
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
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);
}
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_
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