从 python 脚本将文件上传到我的保管箱

2024-01-12

我想自动将文件从 python 脚本上传到我的 Dropbox 帐户。无论如何,我找不到只用用户/通行证来做到这一点。我在 Dropbox SDK 中看到的所有内容都与具有用户交互的应用程序相关。我只想做这样的事情:

https://api-content.dropbox.com/1/files_put/ https://api-content.dropbox.com/1/files_put//?用户=我&密码=废话


的答案是@克里斯蒂娜 https://stackoverflow.com/a/23895259/8565438基于 DropboxAPP v1 https://www.dropbox.com/developers-v1/core/docs/python,现已弃用并将于 6/28/2017 关闭。 (请参阅here https://blogs.dropbox.com/developers/2016/06/api-v1-deprecated/了解更多信息。)

APP v2 https://www.dropbox.com/developers/documentation/python#overview于2015年11月推出,更简单、更一致、更全面。

这是 APP v2 的源代码。

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import dropbox

class TransferData:
    def __init__(self, access_token):
        self.access_token = access_token

    def upload_file(self, file_from, file_to):
        """upload a file to Dropbox using API v2
        """
        dbx = dropbox.Dropbox(self.access_token)

        with open(file_from, 'rb') as f:
            dbx.files_upload(f.read(), file_to)

def main():
    access_token = '******'
    transferData = TransferData(access_token)

    file_from = 'test.txt'
    file_to = '/test_dropbox/test.txt'  # The full path to upload the file to, including the file name

    # API v2
    transferData.upload_file(file_from, file_to)

if __name__ == '__main__':
    main()

源代码托管在 GitHub 上,here https://github.com/sparkandshine/tools/tree/master/dropbox/transferdata.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从 python 脚本将文件上传到我的保管箱 的相关文章

随机推荐