Answer the question
In order to leave comments, you need to log in
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
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']}"})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question