我想获得Dropbox目录,如" c:\ Users \ foo \ Dropbox"或" / Users / foo / Dropbox"用ruby。
有一种简单的方法吗?
答案 0 :(得分:1)
# Install this the SDK with "gem install dropbox-sdk"
require 'dropbox_sdk'
# Get your app key and secret from the Dropbox developer website
APP_KEY = 'INSERT_APP_KEY'
APP_SECRET = 'INSERT_APP_SECRET'
flow = DropboxOAuth2FlowNoRedirect.new(APP_KEY, APP_SECRET)
authorize_url = flow.start()
# Have the user sign in and authorize this app
puts '1. Go to: ' + authorize_url
puts '2. Click "Allow" (you might have to log in first)'
puts '3. Copy the authorization code'
print 'Enter the authorization code here: '
code = gets.strip
# This will fail if the user gave us an invalid authorization code
access_token, user_id = flow.finish(code)
client = DropboxClient.new(access_token)
puts "linked account:", client.account_info().inspect
file = open('working-draft.txt')
response = client.put_file('/magnum-opus.txt', file)
puts "uploaded:", response.inspect
root_metadata = client.metadata('/')
puts "metadata:", root_metadata.inspect
在这个阶段,你可能会比为每个root_metadata ['内容']调用client.get_file更糟糕,其中root_metadata ['内容'] [' is_dir' ]是假的。如何最好地做到这一点,留作OP的练习。
答案 1 :(得分:1)
较新版本的Dropbox客户端会将包含路径的文件写入Dropbox文件夹,您可以为此目的阅读这些文件夹。您可以在此处找到更多信息:
https://www.dropbox.com/help/4584
简而言之,您可以读取该info.json文件并将内容解析为JSON以检索Dropbox文件夹路径。