简体   繁体   中英

How to get list of all files inside a folder on Google Drive using Google Drive api in ruby

Hi guys i am using google-api-client gem in my app i want to get list of all images inside a folder how can i achieve it. here is my code to get list of all files on first page only.

require 'google/apis/drive_v2'
require 'signet/oauth_2/client'
require 'googleauth'

Drive = Google::Apis::DriveV2 # Alias the module
drive = Drive::DriveService.new
drive.authorization = authorization
files = drive.list_files

please let me know how i can get a list of all files inside a folder. like i have a folder named 'test_folder' and i have some files inside that folder now i want to get list of all files. please help me.

You need to use parameter q with value '#{folder_id}' an parents

If the folder is in a shared drive, you need to set supports_all_drives and include_items_from_all_drives to true .

Below is my code to look for files with specified name in a specified folder in shared drive.

query = "name = '#{file_name}' and '#{FOLDER_ID}' in parents"

response = drive_service.list_files(
    q: query,
    fields: "files(id, name)",
    supports_all_drives: true,
    include_items_from_all_drives: true
)

Hope this help

Here give this a shot.

service = Google::Apis::DriveV2::DriveService.new
service.client_options.application_name = APPLICATION_NAME
service.authorization = authorize
# List the 10 most recently modified files.
response = service.list_files()
puts 'Files:'
puts 'No files found' if response.items.empty?
response.items.each do |file|
  puts "#{file.title} (#{file.id})"
end

for more information see the documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM