nextcloud api python 示例

安装nextcloud

docker pull nextcloud

运行

docker run -d -p 80:80 nextcloud

创建管理员账号(因为忘记截图了)


nextcloud api python 示例_第1张图片
image.png

页面详情


nextcloud api python 示例_第2张图片
image.png

python调用nextcloud api

下载nextcloud api Python安装包
python3
github 地址
下载
pip install ***

python 接口调用

# -*- coding: utf-8 -*-
from nextcloud import NextCloud

NEXTCLOUD_URL = 'http://localhost'
NEXTCLOUD_USERNAME = 'admin'
NEXTCLOUD_PASSWORD = 'admin'
to_js = True

nxc = NextCloud(endpoint=NEXTCLOUD_URL, user=NEXTCLOUD_USERNAME, password=NEXTCLOUD_PASSWORD, json_output=to_js)
# 获取用户的列表
a = nxc.get_users()
print(a.data)


# 获取用户的文件夹信息
c = nxc.list_folders('admin')
print(c.data)

# 上传图片
local_filepath = '/Users/zexin.zhang/Pictures/pap.er/8.jpg'
upload_filepath = 'Photos/8.jpg'

b = nxc.upload_file('admin', local_filepath, upload_filepath)
print(b.data)

# 分享图片拿到公共链接
d = nxc.create_share('Photos/8.jpg', 3)

print(d.data)

d_data = {'id': '1', 'share_type': 3, 'uid_owner': 'admin', 'displayname_owner': 'admin', 'permissions': 1,
          'stime': 1566884948, 'parent': None, 'expiration': None, 'token': 'nc5kJe8k7ATCHy2',
          'uid_file_owner': 'admin', 'note': '', 'label': '', 'displayname_file_owner': 'admin',
          'path': '/Photos/8.jpg', 'item_type': 'file', 'mimetype': 'image/jpeg', 'storage_id': 'home::admin',
          'storage': 2, 'item_source': 151, 'file_source': 151, 'file_parent': 8, 'file_target': '/8.jpg',
          'share_with': None, 'share_with_displayname': None, 'password': None, 'send_password_by_talk': False,
          'url': 'http://localhost/s/nc5kJe8k7ATCHy2', 'mail_send': 1, 'hide_download': 0}

你可能感兴趣的:(nextcloud api python 示例)