Google ドライブ Ruby クライアントを使用しており、いくつかのシート ドキュメントを CSV 形式にエクスポートしようとしています。ファイルを正常に取得できますが、アクセスしようとするとexportLinks
、Google のサイトの API Explorer でファイルが返されますが、ファイルに存在しないようです。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 Explorer ではまだ更新されていませんか? 他に愚かな間違いを犯していますか? どこかでコンマが抜けていませんか? 何か助けはありますか?非常に感謝!
さらにコードが必要な場合はお知らせください。
編集 -- スタック トレース:
/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 Explorer は、取得する必要があることを示しています。
"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"
},