1
我想編寫代碼,使用Dropbox API可以下載指定文件夾中的所有圖像,而不是Dropbox中的子文件夾。到目前爲止,我已經寫了這個使用dropbox API下載指定文件夾中的所有圖像而不是子文件夾API
def download_cont(self, folderName):
fname = folderName
folder_metadata = self.client.metadata('/' + fname)
print folder_metadata
這是元數據:
{u'size': u'0 bytes', u'hash': u'3fad7ce5537e0941f8768413cdb7b84d', u'bytes': 0, u'thumb_exists': False, u'rev': u'111c24338d', u'modified': u'Sun, 22 Dec 2013 02:09:41 +0000', u'path': u'/images', u'is_dir': True, u'icon': u'folder', u'root': u'dropbox', u'contents': [{u'size': u'56.2 KB', u'rev': u'131c24338d', u'thumb_exists': True, u'bytes': 57538, u'modified': u'Sun, 22 Dec 2013 02:16:34 +0000', u'mime_type': u'image/png', u'path': u'/images/296px-Manchester_United_FC_crest.svg.png', u'is_dir': False, u'icon': u'page_white_picture', u'root': u'dropbox', u'client_mtime': u'Sun, 22 Dec 2013 02:16:34 +0000', u'revision': 19}, {u'size': u'9.8 KB', u'rev': u'141c24338d', u'thumb_exists': True, u'bytes': 9999, u'modified': u'Sun, 22 Dec 2013 02:16:36 +0000', u'mime_type': u'image/jpeg', u'path': u'/images/images.jpg', u'is_dir': False, u'icon': u'page_white_picture', u'root': u'dropbox', u'client_mtime': u'Sun, 22 Dec 2013 02:16:36 +0000', u'revision': 20}, {u'size': u'77 KB', u'rev': u'151c24338d', u'thumb_exists': True, u'bytes': 78798, u'modified': u'Sun, 22 Dec 2013 02:16:39 +0000', u'mime_type': u'image/jpeg', u'path': u'/images/manchester-united-fc-3d.jpg', u'is_dir': False, u'icon': u'page_white_picture', u'root': u'dropbox', u'client_mtime': u'Sun, 22 Dec 2013 02:16:39 +0000', u'revision': 21}, {u'size': u'220.9 KB', u'rev': u'121c24338d', u'thumb_exists': True, u'bytes': 226209, u'modified': u'Sun, 22 Dec 2013 02:15:51 +0000', u'mime_type': u'image/jpeg', u'path': u'/images/manchester-united-plc-logo.jpg', u'is_dir': False, u'icon': u'page_white_picture', u'root': u'dropbox', u'client_mtime': u'Sun, 22 Dec 2013 02:15:51 +0000', u'revision': 18}, {u'size': u'0 bytes', u'rev': u'161c24338d', u'thumb_exists': False, u'bytes': 0, u'modified': u'Sun, 22 Dec 2013 02:16:53 +0000', u'path': u'/images/sub', u'is_dir': True, u'icon': u'folder', u'root': u'dropbox', u'revision': 22}], u'revision': 17}
從我想我要遍歷JSON對象和元數據使用'contents'
下載的每個文件,但我我不知道如何做到這一點。請幫忙。
感謝您的幫助代碼。然而,我得到這個錯誤'追蹤(最近呼叫最後): 文件「/home/archit/Documents/Dropbox/dropbox-api-dev/first_app_1.0.py」,行91,在 drop.download_cont ('images') 文件「/home/archit/Documents/Dropbox/dropbox-api-dev/first_app_1.0.py」,第53行,在download_cont 與self.client.get_file(路徑)作爲f: AttributeError :HTTPResponse實例沒有屬性'__exit __''。請告訴我錯誤是什麼? –
我猜你在SDK的1.6版本而不是2.0版本(剛剛幾天前發佈)。看到我更新的答案。 – smarx