I
I
igorspesh2019-06-18 20:07:09
Python
igorspesh, 2019-06-18 20:07:09

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

spoiler
через строчку
. there is a python code that uploads only 1 photo. how to upload a photo to an album while saving a link to each, let's say in the links.txt file

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
igorspesh, 2019-06-19
@igorspesh

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')

I
Ivan Yakushenko, 2019-06-18
@kshnkvn

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 question

Ask a Question

731 491 924 answers to any question