Answer the question
In order to leave comments, you need to log in
VK API photos.saveWallPhoto returns Invalid hash. What's wrong?
How to upload a photo to the wall?
1. I get a server to upload
2. I upload a photo
3. I try to save it using the photos.saveWallPhoto method
And then I get an error all the time I
don’t use any SDKs, I send requests using the request module
I tried to send it directly with a curl - the result is the same
So. At step 2, I get the following line in response:
{"server":604318,"photo":"[{\"photo\":\"eea7bb809b:x\",\"sizes\":,\"kid\":\"604eeef2f79a216276b3fc4db69db121\",\"debug\":\"xsxmxxxoxpxqxrx\"}]","hash":"dc4747eab0b9f081ae90211c5b484668"}
photo=[{\"photo\":\"eea7bb809b:x\",\"sizes\":,\"kid\":\"604eeef2f79a216276b3fc4db69db121\",\"debug\":\"xsxmxxxoxpxqxrx\"}]
photo=[{"photo":"eea7bb809b:x","sizes":,"kid":"604eeef2f79a216276b3fc4db69db121","debug":"xsxmxxxoxpxqxrx"}]
Invalid hash
encodeURIComponent
for the photo parameter, I still get Invalid hash
Answer the question
In order to leave comments, you need to log in
He posts a picture on his wall.
VK.Api.call('photos.getWallUploadServer', {}, function (answer) {
up_url = answer.response.upload_url; // получаем upload_url, куда загружать фото
$.ajax({
'type': 'POST',
'url': apiPoint + '/post-send', //экшн моего сервера, ниже приведу его текст
data: {
link: up_url,
file: fileName //имя файла, который я хочу загрузить в вк. Лежит на моем сервере
},
success: function (request) {
request = JSON.parse(request);// параметры для сохранения
// request.user_id = response.session.mid;
VK.Api.call('photos.saveWallPhoto', // сохраняем
request, // передаем параметры полученные от post + uid_того_кому_отправляешь
function (result) { // данные о сохраненном фото
console.log(result.response[0].id);
VK.Api.call('wall.post', // постим на стену
{
// owner_id : result.response[0].owner_id,
attachments: result.response[0].id,
message: inputedTxt
},
function (r) {
if (r.error) {
console.log(r.error);
return false;
}
});
}
);
}
});
});
public function actionPostSend() // это то что было в js как apiPoint + '/post-send'
{
$this->returnFormatJson(); //выставляю возвращаемый формат
$fileName = $this->getRequest('post','file'); // принимаю имя файла
$curl = new CurlHelper();
$rez = $curl->sendFile([
'url' => $this->getRequest('post','link', ''),
'file' => $this->userUpload . DIRECTORY_SEPARATOR . $fileName //физический путь к файлу
]);
return (isset($rez["html"]))
? $rez["html"]
: false;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question