Featured image of post 『 Notes 』Aliyundrive API

『 Notes 』Aliyundrive API

记录目前公开可用的阿里云盘 API

Quick Start

截止至 2021/09/15,Aliyundrive 仍采用 access-token + auto refresh 机制实现用户鉴权以及身份信息的超时更新。

需要通过手动(或额外的自动化操作脚本)的方式「首次」获取 access_tokenrefresh_token 以及 default_drive_id ,之后可携带「更新码」请求相应的接口实现身份信息的自动更新。

Get Token

以任何你喜欢的方式登录 阿里云盘网页版,登陆之后开启调试台 F12

根据这三个参数,可以对普通用户的挂载资源进行增删改查。

Hello World

使用 接口:获取用户信息 测试 Token 是否有效。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import requests

# Change your private information
STATIC_ACCESS_TOKEN = ""
STATIC_REFRESH_TOKEN = ""
DEFAULT_DRIVE_ID = ""


def get_user_info():
    api_url = "https://api.aliyundrive.com/v2/user/get"

    headers = {
        "authorization": STATIC_ACCESS_TOKEN
    }

    session = requests.session()

    response = session.post(api_url, headers=headers, json={})
    
    print(response.json())


if __name__ == '__main__':
    get_user_info()

若一切正常,你将成功获取到如下信息(返回信息仅供演示,此处隐去 private value ):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{
    "domain_id": "",
    "user_id": "",
    "avatar": "",
    "created_at": ,
    "updated_at": ,
    "email": "",
    "nick_name": "",
    "phone": "",
    "role": "user",
    "status": "enabled",
    "user_name": "",
    "description": "",
    "default_drive_id": "",
    "user_data": {
        "back_up_config": {
            "手机备份": {
                "folder_id": "",
                "photo_folder_id": "",
                "sub_folder": {},
                "video_folder_id": ""
            }
        },
        "share": ""
    },
    "deny_change_password_by_self": false,
    "need_change_password_next_login": false,
    "permission": null
}

至此,你已成功配置 authorization-header 并调用 /user/get 接口实现用户信息获取,而几乎所有的公开 API 都仅需此配置即可调用。

Public API

User Group

Get User Info

https://api.aliyundrive.com/v2/user/get

  • info

    获取账号基础信息

  • Header

NameValueDescription
authorizationyour access_tokenaccess_token( 2 小时刷新一次)
  • Body

    1
    
    {}
    
  • Response

  • example

Source Group

与挂载资源相关的接口组。

Get File List

https://api.aliyundrive.com/v2/file/list

  • info

    获取目标挂载区的文件列表标签。

  • Header

NameValueDescription
authorizationyour access_tokenaccess_token( 2 小时刷新一次)详见刷新 token
drive_idyour drive_id磁盘id值
parent_file_idroot上级文件夹路径
limit10每页显示文件数量
allfalse是否显示全部
image_thumbnail_processimage/resize,w_160/format,jpeg图片缩略图类型
order_byupdated_at排序字段
order_directiondesc升序 asce / 降序 desc
fields*字段通配符
  • Body
  • Response
  • example

Get File Details

https://api.aliyundrive.com/v2/file/get

  • info

    获取某个文件实体的详细信息

  • Header

KeyValueNote
authorizationyour access_tokenaccess_token( 2 小时刷新一次)
  • Body

    1
    2
    3
    4
    
    {
        "drive_id":"your drive_id",
    	"file_id":"the file id"
    }
    
  • Response

  • example

Get Download Url

https://api.aliyundrive.com/v2/file/get_download_url

  • info

    拉取某个指定的文件实体

  • Header

KeyValueNote
authorizationyour access_tokenaccess_token(2小时刷新一次)
  • Body

  • Response

  • example

Advanced Work

内联搜索系统

Telegram bot | Inline Queries 服务中将阿里云盘作为超大型文件的内联搜索中间件。

用户组资源映射

使用 AliyunDrive 网页版的现有特性,构建文件秒传通道。

Excellent Work

Reference

Licensed under CC BY-NC-SA 4.0
You will to enjoy grander sight / By climing to a greater height.