googleapis/google-api-ruby-client

list_permissions puts "notFound: File not found:"

Closed this issue · 3 comments

To get list permissions with drive v3 api, I implemented this below,

  • sample.rb
...
CREDENTIALS_PATH = "credentials.json".freeze
# The file token.yaml stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
TOKEN_PATH = "token.yaml".freeze
SCOPE = [
  Google::Apis::DriveV3::AUTH_DRIVE,
  Google::Apis::DriveV3::AUTH_DRIVE_FILE,
  Google::Apis::DriveV3::AUTH_DRIVE_READONLY,
  Google::Apis::DriveV3::AUTH_DRIVE_METADATA_READONLY,
  Google::Apis::DriveV3::AUTH_DRIVE_METADATA,
  Google::Apis::DriveV3::AUTH_DRIVE_PHOTOS_READONLY
]

##
# Ensure valid credentials, either by restoring from the saved credentials
# files or intitiating an OAuth2 authorization. If authorization is required,
# the user's default browser will be launched to approve the request.
#
# @return [Google::Auth::UserRefreshCredentials] OAuth2 credentials
def authorize
...
# List the 10 most recently modified files.
response = drive_service.list_drives(page_size: 100,
                                     use_domain_admin_access: true)
#                                    fields:    "nextPageToken, files(id, name)")
#puts "No files found" if response.files.empty?
response.drives.each do |d|
  puts "#{d.name} (#{d.id})"
  r = drive_service.list_permissions(file_id: d.id,
                                     use_domain_admin_access: true,
                                     include_permissions_for_view: "published",
                                     supports_all_drives: true,
                                     supports_team_drives: true
                                    )
  r.permissions.each do |ps|
    puts "#{ps.id} (#{ps.emailAddress})"
  end
end

Refs.

After all sample.rb put the following and exited,

samplename (sampleid)
Traceback (most recent call last):
	17: from sample.rb:57:in `<main>'
	16: from sample.rb:57:in `each'
	15: from sample.rb:59:in `block in <main>'
	14: from /Library/Ruby/Gems/2.6.0/gems/google-api-client-0.53.0/generated/google/apis/drive_v3/service.rb:1572:in `list_permissions'
	13: from /Library/Ruby/Gems/2.6.0/gems/google-apis-core-0.4.1/lib/google/apis/core/base_service.rb:377:in `execute_or_queue_command'
	12: from /Library/Ruby/Gems/2.6.0/gems/google-apis-core-0.4.1/lib/google/apis/core/http_command.rb:102:in `execute'
	11: from /Library/Ruby/Gems/2.6.0/gems/retriable-3.1.2/lib/retriable.rb:56:in `retriable'
	10: from /Library/Ruby/Gems/2.6.0/gems/retriable-3.1.2/lib/retriable.rb:56:in `times'
	 9: from /Library/Ruby/Gems/2.6.0/gems/retriable-3.1.2/lib/retriable.rb:61:in `block in retriable'
	 8: from /Library/Ruby/Gems/2.6.0/gems/google-apis-core-0.4.1/lib/google/apis/core/http_command.rb:110:in `block in execute'
	 7: from /Library/Ruby/Gems/2.6.0/gems/retriable-3.1.2/lib/retriable.rb:56:in `retriable'
	 6: from /Library/Ruby/Gems/2.6.0/gems/retriable-3.1.2/lib/retriable.rb:56:in `times'
	 5: from /Library/Ruby/Gems/2.6.0/gems/retriable-3.1.2/lib/retriable.rb:61:in `block in retriable'
	 4: from /Library/Ruby/Gems/2.6.0/gems/google-apis-core-0.4.1/lib/google/apis/core/http_command.rb:113:in `block (2 levels) in execute'
	 3: from /Library/Ruby/Gems/2.6.0/gems/google-apis-core-0.4.1/lib/google/apis/core/http_command.rb:310:in `execute_once'
	 2: from /Library/Ruby/Gems/2.6.0/gems/google-apis-core-0.4.1/lib/google/apis/core/http_command.rb:194:in `process_response'
	 1: from /Library/Ruby/Gems/2.6.0/gems/google-apis-core-0.4.1/lib/google/apis/core/api_command.rb:134:in `check_status'
/Library/Ruby/Gems/2.6.0/gems/google-apis-core-0.4.1/lib/google/apis/core/http_command.rb:228:in `check_status': notFound: File not found: file_id,sampleid,use_domain_admin_access,true,include_permissions_for_view,published,supports_all_drives,true,supports_team_drives,true. (Google::Apis::ClientError)

The shared drive(samplename) actually exists and the credentials is attached as administrator.
Can anyone help or advise, please?
Or Should I use the other client such golang instead?

Environment details
OS: macOS Big Sur 11.4
Ruby version: ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]
Gem name and version:
google-api-client (0.53.0)
google-apis-core (0.4.1)
google-apis-discovery_v1 (0.6.0)
google-apis-generator (0.4.0)
googleauth (0.17.0)

Use the google-apis-drive_v3 gem instead of the deprecated google-api-client gem. The latter has an old version of the drive client and is not being updated.

Closing this, assuming the above suggestion successfully addressed the issue. Please feel free to reopen if it is still happening using the latest google-apis-drive_v3 gem.

@dazuma Updated the gem but put the error below, anything else I should try?

% gem list | grep google
fog-google (1.17.0, 0.1.0)
google-apis-compute_v1 (0.19.0)
google-apis-core (0.5.0, 0.4.1)
google-apis-discovery_v1 (0.7.0, 0.6.0)
google-apis-dns_v1 (0.15.0)
google-apis-drive_v3 (0.22.0)
google-apis-generator (0.4.0)
google-apis-iamcredentials_v1 (0.8.0)
google-apis-monitoring_v3 (0.17.0)
google-apis-pubsub_v1 (0.9.0)
google-apis-sqladmin_v1beta4 (0.20.0)
google-apis-storage_v1 (0.9.0)
google-cloud-env (1.5.0)
googleauth (1.1.0, 0.17.0, 0.13.0)
omniauth-google-oauth2 (1.0.0, 0.8.0)
/Library/Ruby/Gems/2.6.0/gems/google-apis-core-0.5.0/lib/google/apis/core/http_command.rb:230:in `check_status': notFound: File not found: file_id,...,use_domain_admin_access,true,include_permissions_for_view,published,supports_all_drives,true,supports_team_drives,true. (Google::Apis::ClientError)
	from /Library/Ruby/Gems/2.6.0/gems/google-apis-core-0.5.0/lib/google/apis/core/api_command.rb:134:in `check_status'
	from /Library/Ruby/Gems/2.6.0/gems/google-apis-core-0.5.0/lib/google/apis/core/http_command.rb:196:in `process_response'
	from /Library/Ruby/Gems/2.6.0/gems/google-apis-core-0.5.0/lib/google/apis/core/http_command.rb:312:in `execute_once'
	from /Library/Ruby/Gems/2.6.0/gems/google-apis-core-0.5.0/lib/google/apis/core/http_command.rb:115:in `block (2 levels) in execute'
	from /Library/Ruby/Gems/2.6.0/gems/retriable-3.1.2/lib/retriable.rb:61:in `block in retriable'
	from /Library/Ruby/Gems/2.6.0/gems/retriable-3.1.2/lib/retriable.rb:56:in `times'
	from /Library/Ruby/Gems/2.6.0/gems/retriable-3.1.2/lib/retriable.rb:56:in `retriable'
	from /Library/Ruby/Gems/2.6.0/gems/google-apis-core-0.5.0/lib/google/apis/core/http_command.rb:112:in `block in execute'
	from /Library/Ruby/Gems/2.6.0/gems/retriable-3.1.2/lib/retriable.rb:61:in `block in retriable'
	from /Library/Ruby/Gems/2.6.0/gems/retriable-3.1.2/lib/retriable.rb:56:in `times'
	from /Library/Ruby/Gems/2.6.0/gems/retriable-3.1.2/lib/retriable.rb:56:in `retriable'
	from /Library/Ruby/Gems/2.6.0/gems/google-apis-core-0.5.0/lib/google/apis/core/http_command.rb:102:in `execute'
	from /Library/Ruby/Gems/2.6.0/gems/google-apis-core-0.5.0/lib/google/apis/core/base_service.rb:377:in `execute_or_queue_command'
	from /Library/Ruby/Gems/2.6.0/gems/google-apis-drive_v3-0.22.0/lib/google/apis/drive_v3/service.rb:1597:in `list_permissions'
	from sample.rb:59:in `block in <main>'
	from sample.rb:57:in `each'
	from sample.rb:57:in `<main>'