L
L
lapu_lapu2016-08-20 18:03:53
In contact with
lapu_lapu, 2016-08-20 18:03:53

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"}

Problem with the photo parameter, how to send it correctly?
If I send like
photo=[{\"photo\":\"eea7bb809b:x\",\"sizes\":,\"kid\":\"604eeef2f79a216276b3fc4db69db121\",\"debug\":\"xsxmxxxoxpxqxrx\"}]

I get an error:
`One of the parameters specified was missing or invalid: photos_list is invalid`
If I send it as
photo=[{"photo":"eea7bb809b:x","sizes":,"kid":"604eeef2f79a216276b3fc4db69db121","debug":"xsxmxxxoxpxqxrx"}]

I get an error:
Invalid hash
If I use it encodeURIComponentfor the photo parameter, I still get
Invalid hash
a Token with the permissions wall,groups.
What am I doing wrong?
is there an example of a "raw" request via curl?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Decadal, 2016-08-20
@lapu_lapu

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;
    }

sorry for coming with this php.
Hope it helps.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question