How to upload video via the VK api

时间:2015-10-06 08:56:21

标签: api upload vk

I am new at VK api.
I want to upload video via the VK API. I cannot get sample codes in my investigation in google.

Can anyone give me sample code.

2 个答案:

答案 0 :(得分:2)

首先,您需要使用this API方法获取http-url上传视频。

然后你应该用" video_file"制作包含字段的POST请求。它将以二进制模式包含您的视频文件。然后你应该致电video.save  保存更改的方法并获取video_id

答案 1 :(得分:1)

使用requests库:

import requests

with open('upload_file_name', 'rb') as f:
    # use upload url you get from vk via 'video.save' call
    resp = requests.post(vk_upload_url, files={'video_file': f})

    # dumb response check
    if resp.json().get('size'):
        print('upload OK')
    else:
        print('shit happens!')

您可以在vk.api文档中了解详细信息