似乎我必须在这里遗漏一些东西。我正在开发一个简单的应用程序,而且我从Dropbox的教程开始:
# 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 = 'XXXXXXXXXXXXXXX'
APP_SECRET = 'XXXXXXXXXXXXXXX'
CODE = 'QEL2VDUKRj4AAAAAAAAAAcBT_U9GoEvKF2UCXp3h4UA'
flow = DropboxOAuth2FlowNoRedirect.new(APP_KEY, APP_SECRET)
puts flow.start()
access_token, user_id = flow.finish(CODE)
client = DropboxClient.new(access_token)
file = open('working-draft.txt')
response = client.put_file('/magnum-opus.txt', file)
puts "uploaded:", response.inspect
代码似乎只适用于一个请求(或至少一次脚本运行),然后我收到错误:
E:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/dropbox-sdk-1.6.2/lib/dropbox_sdk.rb:69:in `parse_response': invalid_grant (DropboxError)
为了在没有每次授权的情况下使其工作,我该怎么做?
答案 0 :(得分:2)
只需将访问令牌存储在某处,并根据需要重复使用它。
要手动尝试,只需打印出access_token
的值,然后将代码修改为:
access_token = '<value from previous run>'
client = DropboxClient.new(access_token)