Answer the question
In order to leave comments, you need to log in
How to get a link to download an image from a VK message?
I am currently working on a bot, which, as planned, should save sent photos to my album for further use.
However, I can't find any way to get a link to a photo file - all the methods from the documentation are not available with a community key.
So the question is, is it even possible to get this link in 2021 or just some complicated workarounds?
I am writing a bot on a longpool, maybe a callback could play here, but I would like to know if there is a way to do this on a long pool.
Answer the question
In order to leave comments, you need to log in
The link to the file is in a lot of places. It is trite to get it from a message if you know its id
params = {'access_token': TOKEN, 'v': 5.131, 'message_ids': [369]}
r = requests.get('https://api.vk.com/method/messages.getById', params=params)
print(r.json()['response']['items'][0]['attachments'][0]['photo']['sizes'])
r = requests.get('{server}?act=a_check&key={key}&ts={ts}&wait=90'.format(server=data['server'], key=data['key'], ts=data['ts'])).json()
print(r['updates'][0]['object']['message']['attachments'][0]['photo']['sizes'])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question