Answer the question
In order to leave comments, you need to log in
How to upload pictures to a VK group album?
I have a folder with a photo that needs to be fully uploaded to the group album. There is a filelist.txt file with the name and extension of all photos
Answer the question
In order to leave comments, you need to log in
import requests
import json
import re
token = '!!!!!с photos привелегией!!!!!!'
version = '5.95'
group = 'id группы'
alb = 'id альбома'
img = 'путь до папки с картинками'
adres = '' #оставлять пустым
img_url = '' #оставлять пустым
chek = int(0)
f = open('filelist.txt') # filelists.txt <- файл с названием.расширением фото(построчно)
line = f.readline().rstrip('\r\n')
while line:
adres = img + line
print(chek)
chek += int(1)
def get_url():
r = requests.get('https://api.vk.com/method/photos.getUploadServer',
params={
'access_token': token,
'album_id': alb,
'group_id': group,
'v': version
}).json()
return r['response']['upload_url']
url = get_url()
file = {'file1': open(adres, 'rb')}
ur = requests.post(url, files=file).json()
result = requests.get('https://api.vk.com/method/photos.save',
params={
'access_token': token,
'album_id': ur['aid'],
'group_id': ur['gid'],
'server': ur['server'],
'photos_list': ur['photos_list'],
'hash': ur['hash'],
'v': version,
}).json()
open(adres).close
line = f.readline().rstrip('\r\n')
f.close()
print ('finish')
You get the upload address using the getUploadServer method , then send a list of photos using the save method , in response you get a list of uploaded images.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question