我正在尝试使用 Google Ruby API 客户端调用云端硬盘 API 来获取文件的元数据,但收到错误"缺少必需参数:id"。这是代码 - 我做错了什么?(注意:客户端 ID 和密钥在请求访问令牌等时工作正常。错误是"id",而不是"客户端 id"或"文件 id")。
client = Google::APIClient.new
drive = client.discovered_api('drive')
client.authorization.client_id = ENV["GOOGLE_CLIENT_ID"]
client.authorization.client_secret = ENV["GOOGLE_CLIENT_SECRET"]
client.authorization.redirect_uri = "http://..."
client.authorization.access_token = "..."
client.authorization.scope = "https://www.googleapis.com/auth/drive"
result = client.execute(
:api_method => drive.files.get,
:version => 'v2',
:parameters => { 'fileId' => "..."}
)
刚想通。对discovered_api的调用缺少版本号。应该是:
drive = client.discovered_api('drive', 'v2')