Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Общие вопросы по .NET и C# > Vkontakte API проблема с методом status set


Автор: NetWorm 13.11.2010, 06:06
Код

http://api.vkontakte.ru/api.php?api_id=" + aplid + "&method=activity.set&format=XML&v=3.0&sig=" + siginmd5 + "&sid=" + sid + "&text=" + statustext

Так выглядит запрос, отвечает что неверная подпись, она выглядит вот так:
Код

sig = mid + "api_id=" + aplid + "format=XMLmethod=status.settext="+statustext+"v=3.0" + secret

Кто работал с Апи вконтакте прошу не останьтесь равнодушны, заранее спасибо

Автор: Ky7m 13.11.2010, 14:09
А md5 от (mid + "api_id=" + aplid + "format=XMLmethod=status.settext="+statustext+"v=3.0" + secret) считаешь?

Автор: NetWorm 13.11.2010, 14:38
Ky7m, да

Автор: Ky7m 14.11.2010, 00:24
Писал одно время, посмотри мой код:
Код

public struct vkApiRequest
    {
        public string api_id;    
        public string method;
        public string sig;
        public string version;
        public string format;
        public string sid;
        public string mid;
        public string secret;
    }

    class vkApiManager
    {
        private vkApiRequest CurrentApiRequest;
        public vkApiManager(string mid,string sid, string secret)
        {
            CurrentApiRequest.api_id = "api_id=194932"; // <---------------Укажи свой ApplicationID
            CurrentApiRequest.version = "v=3.0";
            CurrentApiRequest.format = "format=xml";
            CurrentApiRequest.mid = mid;
            CurrentApiRequest.sid = "sid="+sid;
            CurrentApiRequest.secret = secret;
        }

        private string MD5Hash(string instr)
        {
            string strHash = string.Empty;

            foreach (byte b in new MD5CryptoServiceProvider().ComputeHash(Encoding.Default.GetBytes(instr)))
            {
                strHash += b.ToString("X2");
            }
            return strHash.ToLower();
        } 
        private string CreateSignature(string param)
        {
          
            string ForSign = CurrentApiRequest.mid;
            ForSign += CurrentApiRequest.api_id;
            ForSign += param;
            ForSign += CurrentApiRequest.format;
            ForSign += CurrentApiRequest.method;
            ForSign += CurrentApiRequest.version;
            ForSign += CurrentApiRequest.secret;

            return MD5Hash(ForSign);
        }
        
        public string GetFriendsWithInfo()
        {

            StringBuilder request_content = new StringBuilder();

            CurrentApiRequest.method = "method=friends.get";
            const string param = "fields= nickname, sex, bdate, city, photo";
            
            request_content.Append("http://api.vkontakte.ru/api.php?");
            request_content.Append(CurrentApiRequest.api_id);
            request_content.Append("&"+param+"&");
            request_content.Append(CurrentApiRequest.format);
            request_content.Append("&");
            request_content.Append(CurrentApiRequest.method);
            request_content.Append("&");
            request_content.Append(CurrentApiRequest.sid);
            request_content.Append("&");
            request_content.Append("sig=" + CreateSignature(param));
            request_content.Append("&");
            request_content.Append(CurrentApiRequest.version);


            HttpWebRequest request = HttpWebRequest.Create(request_content.ToString()) as HttpWebRequest;
            request.Method = "POST";

            request.AllowAutoRedirect = false;


            HttpWebResponse response = request.GetResponse() as HttpWebResponse;
            StreamReader myStreamReader = new StreamReader(response.GetResponseStream());
            
            string ret = myStreamReader.ReadToEnd();
            
            response.GetResponseStream().Close();

            return ret;

        }
    }


Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)