我正在使用Google Drive Ruby客户端,并试图将一些表格文档导出为CSV格式。我可以得到我的文件很好,但当试图访问exportLinks
它似乎不存在于我的文件,即使它返回它在谷歌的网站上的API浏览器。以下是我目前试图获得exportLink
的方式:
client = Google::APIClient.new(:application_name => APPLICATION_NAME)
client.authorization = authorize
drive_api = client.discovered_api('drive', 'v2')
result = client.execute!(
:api_method => drive_api.files.get,
:parameters => {:fileId => "1MBP9Q9Q-9ZgLoYnY8ExS-EcxHLESI_vcK4J91ngp6-Q"})
file = result.data
puts("Fetched #{file["title"]}")
puts("Getting downloadURL")
exportLinks = file['exportLinks']['text/csv']
我一直得到一个错误说"未定义的方法'[]'为nil:NilClass (NoMethodError)。"所以出于某种原因,我没有从exportLinks
得到任何返回。有人知道为什么吗?API资源管理器上的方法是否已更改,但尚未更新?我是不是又犯了什么愚蠢的错误?我是不是漏掉了一个逗号?任何帮助都非常感谢!
如果你需要更多的代码,请告诉我。
编辑——堆栈跟踪:
/usr/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /Users/billluhmann/Developer/OpinionLab-Automation/autoimport.rb
Doing some Google Drive stuff
Fetched Test Spreadsheet
Getting downloadURL
/Users/billluhmann/Developer/OpinionLab-Automation/autoimport.rb:163:in `main': undefined method `[]' for nil:NilClass (NoMethodError)
from /Users/billluhmann/Developer/OpinionLab-Automation/autoimport.rb:237:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'
Process finished with exit code 1
编辑2:我注销了我得到的回复…它确实不包括exportLinks。下面是我的应用程序看到的响应的(相关部分):
"parents": [
{
"kind": "drive#parentReference",
"id": "0AJj4OUAR-EvNUk9PVA",
"selfLink": "https://www.googleapis.com/drive/v2/files/1MBP9Q9Q-9ZgLoYnY8ExS-EcxHLESI_vcK4J91ngp6-Q/parents/0AJj4OUAR-EvNUk9PVA",
"parentLink": "https://www.googleapis.com/drive/v2/files/0AJj4OUAR-EvNUk9PVA",
"isRoot": true
}
],
"userPermission": {
"kind": "drive#permission",
"etag": ""OAy0CkbWKifm-WnYBAdgx1dwNXA/IGgJsRJ105V1BXysjoqMdW7TLx8"",
"id": "me",
"selfLink": "https://www.googleapis.com/drive/v2/files/1MBP9Q9Q-9ZgLoYnY8ExS-EcxHLESI_vcK4J91ngp6-Q/permissions/me",
"role": "owner",
"type": "user"
},
响应API资源管理器告诉我应该得到:
"parents": [
{
"kind": "drive#parentReference",
"id": "0AJj4OUAR-EvNUk9PVA",
"selfLink": "https://www.googleapis.com/drive/v2/files/1MBP9Q9Q-9ZgLoYnY8ExS-EcxHLESI_vcK4J91ngp6-Q/parents/0AJj4OUAR-EvNUk9PVA",
"parentLink": "https://www.googleapis.com/drive/v2/files/0AJj4OUAR-EvNUk9PVA",
"isRoot": true
}
],
"exportLinks": {
"text/csv": "https://docs.google.com/spreadsheets/export?id=1MBP9Q9Q-9ZgLoYnY8ExS-EcxHLESI_vcK4J91ngp6-Q&exportFormat=csv",
"application/pdf": "https://docs.google.com/spreadsheets/export?id=1MBP9Q9Q-9ZgLoYnY8ExS-EcxHLESI_vcK4J91ngp6-Q&exportFormat=pdf",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "https://docs.google.com/spreadsheets/export?id=1MBP9Q9Q-9ZgLoYnY8ExS-EcxHLESI_vcK4J91ngp6-Q&exportFormat=xlsx"
},
"userPermission": {
"kind": "drive#permission",
"etag": ""OAy0CkbWKifm-WnYBAdgx1dwNXA/IGgJsRJ105V1BXysjoqMdW7TLx8"",
"id": "me",
"selfLink": "https://www.googleapis.com/drive/v2/files/1MBP9Q9Q-9ZgLoYnY8ExS-EcxHLESI_vcK4J91ngp6-Q/permissions/me",
"role": "owner",
"type": "user"
},
不确定这是否有帮助,但在共享谷歌表的共享设置UI中,我试图使用谷歌驱动器api,如果我选中Disable options to download, print, and copy for commenters and viewers
复选框,那么来自谷歌的json响应将不包括exportLinks条目