Home php Error invalid hash when saving pictures on the wall Group

Error invalid hash when saving pictures on the wall Group

Author

Date

Category

I do all kind of documentation. First, I get the address of the server to download the photos

$ sRequest = "https://api.vkontakte.ru/method/photos.getWallUploadServer?group_id=". $ group_id "& amp; access_token =".. $ access_token;

Then I form a POST request to this address

$ post_params = array (
 'File1' = & gt; '@'. $ PhotoPath2,
 );
 $ Ch = curl_init ($ oResponce- & gt; response- & gt; upload_url);
 CURL_SETOPT ($ CH, CURLOPT_POST, 1);
 curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, false);
 curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, false);
 curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post_params);
 $ Response = curl_exec ($ ch);
 curl_close ($ ch);

It all works as it should, in response to return data of this type string (538) "{" server ": 759255," photo ":" [{\ "photo \": \ "5c0ee7b56f: x \" , \ "sizes \": [[\ "s \", \ "618520954 \", \ "a410 \", \ "Iosmd2gQnbE \", 75,46], [\ "m \", \ "618520954 \" , \ "a411 \", \ "Rtee5OfIEAI \", 130,80], [\ "x \", \ "618520954 \", \ "a412 \", \ "YBQDYZywmI0 \", 550,337], [\ "o \ ", \" 618520954 \ ", \" a413 \ ", \" x-oLJQgm2RI \ ", 130,87], [\" p \ ", \" 618520954 \ ", \" a414 \ ", \" P2urHyRL8vw \ ", 200,133], [\" q \ ", \" 618520954 \ ", \" a415 \ ", \" 281yPf5bAc0 \ ", 320,213], [\" r \ ", \" 618520954 \ ", \" a416 \ ", \" JdxpKBE6ih8 \ ", 510,337]], \" kid \ ": \" 62ebb35ee2e5395151f63bd0d8efbae0 \ "}]", "hash": "7ab875310ab0cb8e53d3fd4ba6e5369b"} "– is a string, which I cut to separate components of server photo and hash. The variable $ server gets the value of 759,255, in the $ photo - 5c0ee7b56f , in hash - 7ab875310ab0cb8e53d3fd4ba6e5369b . Then I call the method photos.saveWallPhoto

$ rsRequest = "https://api.vkontakte.ru/method/photos.saveWallPhoto?group_id=". $ group_id "& amp; access_token =".. $ access_token "& amp; photo =".. $ photo "& amp; server =".. $ server "& amp; hash =".. $ hash;
 $ RoResponce = json_decode (file_get_contents ($ rsRequest));
 var_dump ($ roResponce);

Every time I catch the error Invalid hash. What am I doing wrong? Like all of the documentation.


Answer 1, Authority 100%

Here’s a quote from the document

Note that the server’s response
always comes in JSON format, and field
server, photo and hash it contains
line, which internal format
It may change over time. V
Specifically, the string can photo
contain another json-object that
should not decode, disassemble
part of, or otherwise modify.

That is, photo should get

"[{\" photo \ ": \" 5c0ee7b56f: x \ ", \" sizes \ ": [ [\ "s \", \ "618520954 \", \ "a410 \", \ "Iosmd2gQnbE \", 75,46], [\ "m \", \ "618520954 \", \ "a411 \", \ "Rtee5OfIEAI \", 130,80], [\ "x \", \ "618520954 \", \ "a412 \", \ "YBQDYZywmI0 \", 550,337], [\ "o \", \ "618520954 \" , \ "a413 \", \ "x-oLJQgm2RI \", 130,87], [\ "p \", \ "618520954 \", \ "a414 \", \ "P2urHyRL8vw \", 200,133], [\ "q \", \ "618520954 \", \ "a415 \", \ "281yPf5bAc0 \", 320,213], [\ "r \", \ "618520954 \", \ "a416 \", \ "JdxpKBE6ih8 \" , 510,337]], \ "kid \": \ "62ebb35ee2e5395151f63bd0d8efbae0 \"}] "

Answer 2

upload_url = self.vk_api.photos.getWallUploadServer (group_id = config.vk_group_id, v = '5.73') [ ' upload_url ']
  request = requests.post (upload_url, files = { 'photo': open ( "Penguins.jpg", "rb")})
  print (request.json ())
  params = { 'server': request.json () [ 'server'],
       'Photo': request.json () [ 'photo'],
       'Hash': request.json () [ 'hash'],
       'Group_id': -config.vk_group_id,
       'V': '5.73'}
  photo_id = self.vk_api.photos.saveWallPhoto (** params) [0] [ 'id']
  params = { 'attachments': photo_id,
       'Owner_id': config.vk_group_id,
       'From_group': '1'}
  self.vk_group_api.wall.post (** params)

as the author sends the image in saveWallPhoto as advised prokidyval total field photo from the previous step, but the error still:

vk.exceptions.vkapierror: 121. INVALID HASH. Request_params = {‘Oauth’: ‘1’, ‘Method’: ‘Photo.SaveWallPhoto’, ‘Server’: ‘834404’, ‘Photo’: ‘[{“Photo”: “43ED4DC030: Z”, “Sizes”: [[“S”, 834404069, “DA1C1”, “UZRHSO8NIKC”, 75,56], [“M”, 834404069, “DA1C2”, “AZLFXQLK0OI”, 130,97], [“X”, 834404069, “DA1C3 “,” Zy9gtx0-q44 “, 604,453], [” y “, 834404069,” da1c4 “,” jjauvjfldau “, 807,605], [” z “, 834404069,” DA1C5 “,” MK9RKDISM0Q “, 1024,768], [ “O”, 834404069, “DA1C6”, “PJCSEZYVKAA”, 130,98], [“P”, 834404069, “DA1C7”, “FYKEIMVMVK8”, 200,150], [“Q”, 834404069, “DA1C8”, “CH3QZ -G67A0, 320,240], [“R”, 834404069, “DA1C9”, “DTM4J2JRMOA”, 510,383]], “Latitude”: 0, “Longitude”: 0, “Kid”: “7E803BFA8287365BA577A42AB4E579F7”}] ‘,’ hash ‘:’ d9f5c3f00db055d84cd0bf52e9deb4c8 ‘,’ group_id ‘:’ ******** ‘,’ V ‘:’ 5.73 ‘}


Answer 3

json_decode (string (538) from this variable, true)

return an array where all the parameters

will be

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions