M
M
mitikostya2015-12-09 20:37:29
In contact with
mitikostya, 2015-12-09 20:37:29

vk API. How to upload photos in a private message?

I'm trying, I mean, upload a photo to the VK dialog, I use the Vk.Net library for C # for this

var imageFile = "C:\\имя_картинки.jpeg"

              var uploadServer = api.Photo.GetMessagesUploadServer(); //Получаем ссылку на сервер для загрузок
              var uploadServerUri = uploadServer.UploadUrl;
              var uploader = new WebClient();
              var uploadResponseInBytes = uploader.UploadFile(uploadServerUri, imageFile); // Загружаем фото на сервер
              var uploadResponseInString = Encoding.UTF8.GetString(uploadResponseInBytes); 

              var jsonObject = (JObject)JsonConvert.DeserializeObject(uploadResponseInString);
              var photoParameter = jsonObject["photo"].ToString(); // вынимаем photo из ответа (исп. Newtonsoft.json)

Here is the photo returned:

[{"photo":"49c64fbb0a:w","sizes":,"kid":"92e5a11b70f880ac622c7fea7f5aba7c","debug":"xswmwxwywzwwwowpwqwrw"}]

Next, I save it:
var photo = api.Photo.SaveMessagesPhoto(photoParameter);

Here is the error it returns:

error: {
error_code: 118,
error_msg: 'Invalid server',
request_params: [{
key: 'oauth',
value: '1'
}, {
key: 'method',
value: 'photos.saveMessagesPhoto'
}, {
key: 'photo',
value: '[{"photo":"49c64fbb0a:w","sizes":[["s","629526621","21260","6Jkf9T9YZjE",58,75],["m","629526621" ,"21261","4YmH_tNjSBc",100,130],["x","629526621","21262","LvxGnkaZwL8",464,604],["y","629526621","21263","O21xjup4jp4",620,807 ],["z","629526621","21264","v2kvn2V540o",830,1080],["w","629526621","21265","v76d9glIcJo",922,1200],["o" ,"629526621","21266","ihP89qpXY1E",130,169],["p","629526621","21267","i1SUBQRgNtM",200,260],["q","629526621","21268","
{
key: 'v',
value: '5.40'
}]
}

How to be? I have already re-read a bunch of guides, googled all the possible formulations of my problem, no one has ever met anything like this.

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
A
Andrew, 2015-12-09
@misterfil

...

error_code: 118,
error_msg: 'Invalid server',

...
Invalid server.
Returns the address of the server to upload the photo to...
Saves the photo after a successful upload to the URI
Might be a bug here
I guess it should be like this
var uploadServerUri = uploadServer.upload_url;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question