I
I
ibr_982017-09-13 16:38:54
Python
ibr_98, 2017-09-13 16:38:54

How to use attachments?

Hello!
Please tell me how to use the attribute attachmentsin, vk api?
for example, I want to post this photo " https://pp.userapi.com/c836328/v836328573/61cb1/9O... " to my group, what do I need to do for this?

vk.wall.post(owner_id=group, from_group=1, attachments=?)

Thank you

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Serezha, 2017-09-13
Ahen @Ahen

According to the link, no way. You must first download the image, and then upload it to the VK server.
It is possible not to re-upload if we have an id and an owner id, optionally an access_key to attach a non-shared attachment.
Everything is well described in the documentation:

список объектов, приложенных к записи и разделённых символом ",". 
Поле attachments представляется в формате:
<type><owner_id>_<media_id>,<type><owner_id>_<media_id>
Например:
photo100172_166443618,photo-1_265827614

I
Ivan Mikhailov, 2017-09-14
@IvanMikhaylov

Using vk_api module (upload to group):

upload = vk_api.VkUpload(vk_session)
foto = upload.photo('PATH/foto.jpg', album_id="id_альбома", group_id="id_группы")
vk_photo_url = 'https://vk.com/photo{}_{}'.format(foto[0]['owner_id'], foto[0]['id'])
photo.append(vk_photo_url.replace('https://vk.com/', ''))

You get a photo in the format photo-123456_123456
Well, something like this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question