Nel*_*llo 3 ruby google-drive-api
这似乎是一个基本问题,但我现在已经进入第二天了:(
我在这里使用Google Drive Ruby Api:https://github.com/google/google-api-ruby-client但README中的基本文件示例似乎已过时.特别是,调用Drive.update_file不要像显示的参数那样.
到目前为止,我可以获得授权的DriveService:
drive = Google::Apis::DriveV3::DriveService.new
drive.authorization = Google::Auth.get_application_default(['https://www.googleapis.com/auth/drive'])
Run Code Online (Sandbox Code Playgroud)
我可以得到一个文件:
file_id = 'string-of-stuff'
file = drive.get_file file_id
Run Code Online (Sandbox Code Playgroud)
我可以在File对象上设置看起来没问题的属性:
file.update!(name: 'My new name')
Run Code Online (Sandbox Code Playgroud)
但是,我无法弄清楚如何在此之后让更新/补丁真正起作用.自述文件建议drive.update_file(file),但只是爆炸类型错误.
TypeError: Can't convert Google::Apis::DriveV3::File into String or Array.
Run Code Online (Sandbox Code Playgroud)
查看代码,#update_file实际上期望一个file_id作为第一个参数.
我已经尝试了基于README的各种变体,例如:
drive.update_file(file_id, {name: 'New name'})
Run Code Online (Sandbox Code Playgroud)
要么:
drive.update_file(file_id, {title: 'New name'})
Run Code Online (Sandbox Code Playgroud)
或(查看代码):
drive.update_file(file_id, fields: {title: 'New name'})
Run Code Online (Sandbox Code Playgroud)
甚至:
drive.update_file(file_id, file)
Run Code Online (Sandbox Code Playgroud)
爆炸与:
Google::Apis::ClientError: fieldNotWritable: The resource body includes fields which are not directly writable.
Run Code Online (Sandbox Code Playgroud)
但没有什么对我有用.有没有人用过这个图书馆?其他一切看起来都相当简单,但这只是很难.
好吧,经过更多的反复试验,这个API工作的唯一方法就是使用一个新 File对象.如果你get_file用来获取你的File,那么你最终得到一个具有不可写id字段的对象.
所以,这 - 只有这一点 - 似乎有效:
drive.update_file(file_id, Google::Apis::DriveV3::File.new(name: name))
Run Code Online (Sandbox Code Playgroud)
叹.
| 归档时间: |
|
| 查看次数: |
441 次 |
| 最近记录: |