Я использую Quickblox в своем приложении C# (Xamarin). Мне не удалось передать код Windows Phone, поэтому я решил использовать API RESTful.Как получить токен в Quickblox?
У меня проблемы с получением жетона. Я последовал this tutorial и вот мой код:
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;
}
В результате я получаю исключение «422: Unprocessable Entity» при попытке получить httpWReq.GetResponse()
Вы можете поделиться своей хеш-функцией? спасибо – Lakshay