ruby の google-drive-api ライブラリを使用して Google ドライブにフォルダを作成できません。正常にログインし、フォルダを一覧表示し、ルート フォルダにファイルを追加することさえできます。ルートフォルダーの下に「Applications」というフォルダーがあります。すべてのファイルを一覧表示すると、このフォルダーの ID が表示されます。「0BwiVxEBt」と呼びましょう。コントローラーで、Google ドライブ接続を正常に初期化し (すべてのファイルを一覧表示できるため)、create_parent('Test') メソッドを呼び出します。私のgoogle_drive_connection.rbにあります:
def create_folder (title)
file = @drive.files.insert.request_schema.new({
'title' => title,
'description' => title,
'mimeType' => 'application/vnd.google-apps.folder'
})
file.parents = [{"id" => '0BwiVxEBt'}] # 0BwiVxEBt is id for Applications folder
media = Google::APIClient::UploadIO.new(title, 'application/vnd.google-apps.folder')
result = @client.execute(
:api_method => @drive.files.insert,
:body_object => file,
:media => media,
:parameters => {
'uploadType' => 'multipart',
#'convert' => false,
'alt' => 'json'})
if result.status == 200
return result.data
else
puts "An error occurred: #{result.data['error']['message']}"
return nil
end
end
他の投稿で見たフォルダーの挿入は、ファイルの挿入 (この rb ファイルの別のメソッドで正常に動作します)、拡張子のないタイトル、および mimeType を 'application/vnd.google-apps.folder として行うのと同じです。 '
エラー: そのようなファイルまたはディレクトリはありません - テスト
おそらく小さな問題ですが、見つからないようです!
提供されたポインタ/ヘルプに感謝します。
EDIT 問題が見つかったので、ソリューションに興味のある人は、フォルダーの場合、リクエストでメタデータを送信するだけで済み、メディア部分は必要なく、本体(メタデータ)情報が必要なだけなので、「create_folder」メソッドの結果は次のようになります。
def create_folder (title)
file = @drive.files.insert.request_schema.new({
'title' => title,
'description' => title,
'mimeType' => 'application/vnd.google-apps.folder'
})
file.parents = [{"id" => '0BwiVxEBt'}] # 0BwiVxEBt is id for Applications folder
result = @client.execute(
:api_method => @drive.files.insert,
:body_object => file)
if result.status == 200
return result.data
else
puts "An error occurred: #{result.data['error']['message']}"
return nil
end
end