Answer the question
In order to leave comments, you need to log in
How to attach a description to a VK image?
Does anyone know how to attach a description to a photo? I know that this is the photos.saveWallPhoto method, the "caption" field.
I just can't figure out how to do it in the vk_api library with a couple of lines.
It doesn't matter if the description is for one image or two.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
__author__ = 'ipetrash'
import vk_api
from vk_api import VkUpload
# Авторизация по логину/паролю (если нужно по токену, заполнять параметр token)
login, password = 'login', 'pass'
app_id = '5182501'
vk_session = vk_api.VkApi(login, password, app_id)
vk_session.auth()
upload = VkUpload(vk_session) # Для загрузки изображений
photos = ['1.jpg', '2.jpg']
# Или:
# photos = [open('1.jpg', 'rb'), open('2.jpg', 'rb')]
photo_list = upload.photo_wall(photos)
attachment = ','.join('photo{owner_id}_{id}'.format(**item) for item in photo_list)
vk_session.method("wall.post", {
'owner_id': '-171537373', # Посылаем себе на стену
'message': 'Test!',
'attachment': attachment,
})
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