M
M
Maksim Tynkovich2022-02-14 21:54:15
API
Maksim Tynkovich, 2022-02-14 21:54:15

VK API CreateComment method, image loading?

How to implement uploading photos as in *example* , according to the VK documentation, you need to upload photos to an album, then take an ID and attach it, in the example some other method is clearly used, or if there is a way how to take a link to a photo from another group and attach it like on behalf of the group in which the bot works, I will be grateful for any advice.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maksim Tynkovich, 2022-02-15
@wildfires

Solution:
session = vk_api.VkApi(token = 'token') // User token
id_group = 210610129
session.method('wall.createComment', {'owner_id': -id_group, 'post_id': 516, 'from_group': id_group , 'message': 'test'})
server = session.method('photos.getWallUploadServer', {'group_id': id_group})
req = requests.post(server['upload_url'], files={'photo': open(f'path/file','rb')}).json()
photo = session.method('photos.saveWallPhoto', {'group_id': id_group, 'photo': req['photo'], ' server': req['server'], 'hash': req['hash']})
session.method('wall.createComment',{'owner_id': -id_group, 'post_id': 516, 'from_group': id_group, 'attachments': f"photo{photo[0]['owner_id']}_{photo[0]['id']}"})

C
cringeg, 2022-02-15
@cringeg

Use the photos.getUploadServer and photos.save methods with a user token. When creating an album, check the box "Photos can be added only by editors and administrators." And they must upload to the album with the token of the creator or administrator.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question