Hello. There is just a script that posts a text entry on the VK wall:

import vk my_app_id = ****** user_login = '******' user_password = '*****' session = vk.AuthSession(scope='wall', app_id=my_app_id, user_login=user_login, user_password=user_password) vk.api.access_token = "*********************" api = vk.API(session) api.wall.post(owner_id='*****', message='Привет') 

It is necessary that the photo was attached to the message from the link. I read the documentation, but did not fully understand what was happening.

Thank you in advance.

2 answers 2

 import vk Session = vk.AuthSession( app_id='***', user_login='***', user_password='***', scope='wall, groups' ) vk_api = vk.API(Session) vk_api.wall.post( owner_id=- '***', message='hello world', attachments='photo151911284_440710456' ) # Ссылка на ваше фото 
  • The link i.imgur.com/rv8ue.jpg does not work - andreymal
  • @andreymal is essentially no way to take a picture from this link, because you need to upload extraneous files to them on the server, and for this you need to download a picture. - Pavel Durmanov

The script below will download the photo at the specified URL, upload it to VKontakte and publish it on the current user's wall.

 import requests import vk IMAGE_URL = ... ACCESS_TOKEN = ... vkapi = vk.API(vk.Session(ACCESS_TOKEN)) destination = vkapi.photos.getWallUploadServer() image = requests.get(IMAGE_URL, stream=True) # имя файла значения не имеет, но без него ВК не принимает фотографию data = ("image.jpg", image.raw, image.headers['Content-Type']) meta = requests.post(destination['upload_url'], files={'photo': data}).json() me = vkapi.users.get()[0]['uid'] photo = vkapi.photos.saveWallPhoto(user_id=me, **meta)[0] vkapi.wall.post(user_id=me, attachments=photo['id']) 

Read more about the photo upload protocol in the documentation .