C
C
CleanyBoom2021-04-05 21:54:40
Python
CleanyBoom, 2021-04-05 21:54:40

Direct link to vk ptyhon image?

Any request to vk returns for some reason a link to the album

example
https://sun9-23.userapi.com/impg/HW6MKuX5-qV91MfYL...
, from which there is no way to get a direct link in the bot, and I need to use the sent image for further processing via pip
(I tried the getById method and simple work with the attached file)
photo = atch['photo']
# 1 вариант
photo = atch['photo']
url = photo['sizes'][-1]['url']
# 2 (костыльный)
d = [photo['owner_id'], photo['id'], photo['access_key']]
d = [str(i) for i in d]
n = '_'.join(d)
n = tr.photos.getById(photos=n)

PS There is a direct link in the documentation, but the post on the wall is considered there, when I drive my id I also get an album
606b5ce1c5d65207211325.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
UberPool, 2021-04-05
@UberPool

I used it in my project, try this

message_id = event.message['id']
msg = vk.messages.getById(message_ids=message_id)
owner_id = event.message['from_id']
access_key = msg['items'][0]['attachments'][0]['photo']['access_key']
photo_id = msg['items'][0]['attachments'][0]['photo']['id']
photo = f'photo{owner_id}_{photo_id}_{access_key}'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question