badRequest: The requested conversion is not supported. (Google::Apis::ClientError)
Set27 opened this issue · 2 comments
Hello. I have some problem with export_file method. It's seem like it work time to time
Here is my full code
require 'google/apis/drive_v3'
require 'googleauth'
require 'googleauth/stores/file_token_store'
require 'pry'
OOB_URI = 'urn:ietf:wg:oauth:2.0:oob'
SCOPE = 'https://www.googleapis.com/auth/drive'
CLIENT_SECRETS_PATH = 'private/credentials-2.json'
TOKEN_PATH = 'private/tokens.yaml'
USER_ID = ENV['USER']
class GoogleDriveGetFiles
def call(file_name)
@file_name = file_name
credentials = auth
drive_service = drive_service_auth(credentials)
file_id = get_file(drive_service)
write_in_file(file_id, drive_service)
end
private
def auth
client_id = Google::Auth::ClientId.from_file(CLIENT_SECRETS_PATH)
token_store = Google::Auth::Stores::FileTokenStore.new(file: TOKEN_PATH)
authorizer = Google::Auth::UserAuthorizer.new(client_id, SCOPE, token_store)
credentials = authorizer.get_credentials(USER_ID)
if credentials.nil?
url = authorizer.get_authorization_url(base_url: OOB_URI)
puts "Open #{url} in your browser and enter the resulting code:"
code = gets.chomp
credentials = authorizer.get_and_store_credentials_from_code(
user_id: USER_ID, code: code, base_url: OOB_URI)
end
credentials
end
def drive_service_auth(credentials)
drive_service = Google::Apis::DriveV3::DriveService.new
drive_service.authorization = credentials
drive_service
end
def get_file(drive_service)
files = drive_service.list_files(fields: 'nextPageToken, files(id, name, mimeType)').files
file_id = nil
files.each do |file|
if file.name == @file_name
file_id = file.id
puts file.name
break
end
end
file_id
end
def write_in_file(file_id, drive_service)
# binding.pry
file = drive_service.get_file(file_id)
File.write("output/#{@file_name}.txt", drive_service.export_file(file_id, 'text/plain'))
puts 'Succefully write in file'
end
end
I worked until 7:30PM, now I have
/home/we/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/google-apis-core-0.11.0/lib/google/apis/core/http_command.rb:239:in `check_status': badRequest: The requested conversion is not supported. (Google::Apis::ClientError)
from /home/we/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/google-apis-core-0.11.0/lib/google/apis/core/api_command.rb:135:in `check_status'
from /home/we/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/google-apis-core-0.11.0/lib/google/apis/core/http_command.rb:202:in `process_response'
from /home/we/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/google-apis-core-0.11.0/lib/google/apis/core/http_command.rb:321:in `execute_once'
from /home/we/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/google-apis-core-0.11.0/lib/google/apis/core/http_command.rb:126:in `block (2 levels) in do_retry'
from /home/we/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/retriable-3.1.2/lib/retriable.rb:61:in `block in retriable'
from /home/we/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/retriable-3.1.2/lib/retriable.rb:56:in `times'
from /home/we/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/retriable-3.1.2/lib/retriable.rb:56:in `retriable'
from /home/we/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/google-apis-core-0.11.0/lib/google/apis/core/http_command.rb:123:in `block in do_retry'
from /home/we/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/retriable-3.1.2/lib/retriable.rb:61:in `block in retriable'
from /home/we/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/retriable-3.1.2/lib/retriable.rb:56:in `times'
from /home/we/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/retriable-3.1.2/lib/retriable.rb:56:in `retriable'
from /home/we/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/google-apis-core-0.11.0/lib/google/apis/core/http_command.rb:113:in `do_retry'
from /home/we/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/google-apis-core-0.11.0/lib/google/apis/core/http_command.rb:104:in `execute'
from /home/we/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/google-apis-core-0.11.0/lib/google/apis/core/base_service.rb:418:in `execute_or_queue_command'
from /home/we/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/google-apis-drive_v3-0.37.0/lib/google/apis/drive_v3/service.rb:1064:in `export_file'
from /home/we/ruby/parse/google_drive_get_file.rb:64:in `write_in_file'
from /home/we/ruby/parse/google_drive_get_file.rb:19:in `call'
from main.ruby:10:in `<main>'
get_file method works properly, but export_file doesn't
UPDATE
I found out that if I give public premmison to read only, it's not work. But if I give public premmision to change file, it's work!
Hi @Set27,
Thank you for reaching out to us.
This does not look like a library issue. Github issues are generally to deal with library issues or any feature requests.
For library usage questions, I'd recommend to ask this question on StackOverflow's Google Cloud collective which is the most appropriate for general troubleshooting.
I'm going to close this issue for now, but please let us know if there's anything we can do to help!