S
S
sharkyyy32019-03-24 16:41:09
Python
sharkyyy3, 2019-03-24 16:41:09

How to send a photo from one user to another in VK?

Hello, the question arose how to send a photo from one user to another.
This is what is passed in <<class 'vk_api.bot_longpoll.VkBotMessageEvent'> to 'attachments'

spoiler
'attachments': [{'type': 'photo', 'photo': {'access_key': '56e2d90bbb91ae012b', 'owner_id': 106XXXXXX, 'album_id': -3, 'id': 456242359, 'text': '', 'sizes': [{'height': 75, 'type': 's', 'url': 'https://pp.userapi.com/c852028/v852028876/e7028/1Frca866Q5Q.jpg', 'width': 75}, {'height': 130, 'type': 'm', 'url': 'https://pp.userapi.com/c852028/v852028876/e7029/wuKuedtFiQA.jpg', 'width': 130}, {'height': 604, 'type': 'x', 'url': 'https://pp.userapi.com/c852028/v852028876/e702a/mRla0liqWRg.jpg', 'width': 604}, {'height': 760, 'type': 'y', 'url': 'https://pp.userapi.com/c852028/v852028876/e702b/6YMoHN3_XbY.jpg', 'width': 760}, {'height': 130, 'type': 'o', 'url': 'https://pp.userapi.com/c852028/v852028876/e702c/fHu8F1o6UYs.jpg', 'width': 130}, {'height': 200, 'type': 'p', 'url': 'https://pp.userapi.com/c852028/v852028876/e702d/H5MtTsR9qB8.jpg', 'width': 200}, {'height': 320, 'type': 'q', 'url': 'https://pp.userapi.com/c852028/v852028876/e702e/unE2tVTbrXY.jpg', 'width': 320}, {'height': 510, 'type': 'r', 'url': 'https://pp.userapi.com/c852028/v852028876/e702f/hR3tuUXqzOA.jpg', 'width': 510}], 'date': 1553413111}}], >

It would seem that everything is easy, just pass the message.send method to attachment 'photo106XXXXXX_456242359_56e2d90bbb91ae012b'
. So I wrote the code, it would seem that everything works
atta = event.obj.attachments
buf = []
                for element in atta:
        
                    if element['type'] == 'photo':
                      try:
                             buf.append('photo' + str(element['photo']['owner_id']) + '_' + str(
                             element['photo']['id']) + '_' + str(element['photo']['access_key']))
                             print('в фото есть ключ')
                      except:
                            print('в фото нет ключа')
                            buf.append('photo' + str(element['photo']['owner_id']) + '_' + str(element['photo']['id']))

But everything is not so smooth here, some photos still cannot be sent, and besides, if you send more than 8 photos in one message, nothing <<class 'vk_api.bot_longpoll.VkBotMessageEvent'>happens, the event does not come.
Is there any other way to send messages with attached photos?
Perhaps I would figure it out with saving one photo sent to myself and then sending it to another user, but if there are several of them, then you need to first sort through all the photos, then sort through all the links in the event to find the right size for saving, then save them to yourself and upload to the VK server with subsequent sending, how can this be implemented? And will it be practical at all?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sharkyyy3, 2019-04-10
@sharkyyy3

The problem was an invalid access key. which is transferred to<<class 'vk_api.bot_longpoll.VkBotMessageEvent'>.

D
dimamira, 2020-11-24
@dimamira

I just do it through forward.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question