Reputation: 49728
I'm using Quickblox in my C# (Xamarin) app. I was unable to port Windows Phone code, so I decided you use the RESTful API.
I'm having problems with getting the token. I followed this tutorial and here's my code:
public string Timestamp()
{
long ticks = DateTime.UtcNow.Ticks - DateTime.Parse("01/01/1970 00:00:00").Ticks;
ticks /= 10000000;
return ticks.ToString();
}
public string GetToken()
{
HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create("https://api.quickblox.com/session.xml");
string application_id = "2675";
string auth_key = "rGvHTKPyJJQ8PFR";
string timestamp = Timestamp ();
string auth_secret = "wePb4NG74eZT3eK";
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "application_id=" + application_id;
postData += "&auth_key=" + auth_key;
postData += "×tamp=" + timestamp;
string signature = Hash (auth_secret, postData);
postData += "&signature=" + signature;
byte[] data = encoding.GetBytes(postData);
httpWReq.Method = "POST";
httpWReq.ContentType = "application/x-www-form-urlencoded";
httpWReq.ContentLength = data.Length;
httpWReq.Headers ["QuickBlox-REST-API-Version"] = "0.1.0";
using (Stream stream = httpWReq.GetRequestStream())
{
stream.Write(data,0,data.Length);
}
HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
string responseString = new StreamReader (response.GetResponseStream()).ReadToEnd ();
return responseString;
}
In the result I'm getting an exception "422: Unprocessable Entity" when trying to receive httpWReq.GetResponse()
Upvotes: 3
Views: 1435
Reputation: 18346
You forgot to add nonce parameter.
Also you should use it when generating signature
Upvotes: 2