Cannot add object as hash value in Rake: TypeError: no implicit conversion of DropboxClient into String

Cannot add object as hash value in Rake: TypeError: no implicit conversion of DropboxClient into String

我在 Rake 任务中为我的 DropBox 使用了以下代码:

require 'dropbox_sdk'

ENV['DROPBOX_APP_ACCESS_KEY'] = 'access key'
ENV['DROPBOX_APP_KEY'] = 'key'
ENV['DROPBOX_APP_SECRET'] = 'secret'

flow = DropboxOAuth2FlowNoRedirect.new(ENV['DROPBOX_APP_KEY'], ENV['DROPBOX_APP_SECRET'])
client = DropboxClient.new(ENV['DROPBOX_APP_ACCESS_KEY'])

这部分就是您连接的方式。它来自 API 文档并且工作正常。

但奇怪的是,当我尝试将 client 对象存储到 ENV 哈希中时,我得到:

ENV['DROPBOX_APP_CONNECTION'] = client
TypeError: no implicit conversion of DropboxClient into String

如果我在 IRB 中做同样的事情,它工作正常。即使我创建一个不同的 Hash 而不是 ENV,它也会起作用。

我在 irb 中遇到了同样的错误,这对我来说很有意义。

ENV 用于获取和设置具有字符串值的环境变量。所以你不能在其中存储不是字符串的东西。

我不确定你为什么要这样做?您是否试图将客户转交给其他流程?如果是这样,我建议让其他进程使用您已经存储在 ENV.

中的访问令牌创建自己的客户端