0

I try to call VK method, and it failed with error:

private function deletePost(postId:String):int
        {
            var sigStr:String = FlashVarsVO.user_id + "api_id="+FlashVarsVO.app_id+"method=wall.deletev=3.09bdnOW93DM3Oy5lcSHr4";
            var sig:String = MD5.hash("sigStr");
            var str:String = "http://api.vk.com/api.php?api_id="+FlashVarsVO.app_id+"&method=wall.delete&v=3.0&format=JSON&post_id="+postId+ "&sid="+ FlashVarsVO.access_token +"&sig=" +sig;
            trace(str);

        //  sig = md5(viewer_idname1=value1name2=value2secret)

            var req:URLRequest = new URLRequest(str);
            var uLdr:URLLoader = new URLLoader(req);
            uLdr.addEventListener(Event.COMPLETE, onComplete);
            uLdr.addEventListener(ErrorEvent.ERROR, onErrorHandler);
            uLdr.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

            return 0;
        }

http://api.vk.com/api.php?api_id=1111111&method=wall.delete&v=3.0&format=JSON&post_id=1629&sid=bf472ebcf2eba19cbdb56d86a8bd477603bbd76bd6c5356e4d003815c7cf3a4&sig=62b1265890d247efdd939f616cad1e8d

for this request, vk.com sends me such response:

{"error":{"error_code":4,"error_msg":"Incorrect signature: Session can be expired, revoked by user or connected with different IP address","request_params":[{"key":"api_id","value":"1111111"},{"key":"method","value":"wall.delete"},{"key":"v","value":"3.0"},{"key":"format","value":"JSON"},{"key":"post_id","value":"1629"},{"key":"sid","value":"bf472ebcf2eba19cbdb56d86a8bd477603bbd76bd6c5356e4d003815c7cf3a4"},{"key":"sig","value":"62b1265890d247efdd939f616cad1e8d"}]}}

How to make it workable? Anyone faced with such error?? Thanks.

yozhik
  • 4,644
  • 14
  • 65
  • 98
  • Watch what you are hashing: `var sig:String = MD5.hash("sigStr");` instead of `var sig:String = MD5.hash(sigStr);` – meps Sep 07 '16 at 07:56

1 Answers1

1

This is not an ActionScript question but a vkontakte one. Based on the error message, you obviously need to check the signature and make sure it's built exactly like vkontakte expects.

In this case, my guess is that you first need to alphabetically sort the query parameters before doing the MD5 hash.

Also it seems all the query parameters are appended one after the other with no separator between them. I don't know about vkontakte but other APIs usually expect the parameters to be separated by "&" before hashing them.

laurent
  • 88,262
  • 77
  • 290
  • 428
  • I read about that on vkontakte documentation, but it looks like I am doing all ok, but still something wrong. – yozhik Apr 12 '12 at 14:44
  • http://vk.com/developers.php?oid=-1&p=%D0%92%D0%B7%D0%B0%D0%B8%D0%BC%D0%BE%D0%B4%D0%B5%D0%B9%D1%81%D1%82%D0%B2%D0%B8%D0%B5_%D0%BF%D1%80%D0%B8%D0%BB%D0%BE%D0%B6%D0%B5%D0%BD%D0%B8%D1%8F_%D1%81_API – yozhik Apr 12 '12 at 14:44