Answer the question
In order to leave comments, you need to log in
VKAPI uploading photos to a group?
I want to upload photos to the server. But I don’t understand why the photos_list parameter is required if it is not specified in the documentation.
var VK = require('vksdk');
var unirest = require('unirest');
var vk = new VK({
'appId' : 5496471,
'appSecret' : '******************',
'language' : 'ru'
});
vk.setToken('**********************');
vk.setSecureRequests(true);
vk.request('photos.getWallUploadServer', {'group_id' : 110234774}, function(data) {
console.log(data); // Первый запрос
unirest.post(data.response.upload_url)
.headers({'Content-Type': 'multipart/form-data'})
.attach('file1', 'photo.jpg') // Attachment
.end(function (response) {
console.log(response); // Второй запрос
var resp = JSON.parse(response.body);
var server = resp.server;
var photo = JSON.stringify(resp.photo).replace(/\\/g,'');
var hash = resp.hash;
var gid = '110234774';
vk.request('photos.saveWallPhoto', {'server' : server, 'photo': photo, 'hash':hash, 'group_id':gid}, function(data) {
console.log(data);
console.log(data); // Третий запрос
});
});
});
{ response:
{ upload_url: 'http://cs633719.vk.com/upload.php?act=do_add&mid=366989513&aid=-14&gid=110234774&hash=cc1461536b7025867bca6f9369bbce1d&rhash=acd25af777118327539ab92ecb47b03e&swfupload=1&api=1&wallphoto=1',
album_id: -14,
user_id: 366989513 } }
{"server":633719,"photo":"[{\\"photo\\":\\"67c0e2babf:x\\",\\"sizes\\":,\\"kid\\":\\"5fbd02d96a77ac7583c441b06c50c0a4\\",\\"debug\\":\\"xsxmxxxoxpxqxrx\\"}]","hash":"035e981fb844ead49920dcbdb7f576a6"}
{ error:
{ error_code: 100,
error_msg: 'One of the parameters specified was missing or invalid: photos_list is invalid',
request_params:
[ [Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object] ] } }
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question