Je suis la première fois en utilisant API Google. Je ne parviens pas à télécharger un fichier dans Google Drive. J'ai essayé ci-dessous le code complet.Impossible de télécharger et d'image dans googledrive en utilisant goolge ruby API
require 'google/apis/drive_v2'
require 'google/api_client/client_secrets'
# I downloaded 'client_secrets.json' file from 'https://console.developers.google.com/projectselector/apis/library' and put in lib folder
CLIENT_SECRETS_FILE = "client_secrets.json"
client_secrets_filepath = File.expand_path(CLIENT_SECRETS_FILE ,"#{File.dirname(__FILE__)}/../../lib/")
CLIENT_SECRETS = Google::APIClient::ClientSecrets.load(client_secrets_filepath)
authorization = CLIENT_SECRETS.to_authorization
Drive = Google::Apis::DriveV2
@drive = Drive::DriveService.new
@drive.authorization = authorization
file_path = File.expand_path(@ScreenShot_dir)+'/'+"imageName" +'.png'
metadata = Drive::File.new(title: 'My document')
metadata = @drive.insert_file(metadata, upload_source: file_path, content_type: 'image/png')
Il ne télécharge pas le fichier dans le lecteur mais donne une erreur comme "code d'autorisation manquant".
mes client_secrets.json ressemblent ci-dessous:
{"installed":{
"client_id":"<some digits>.apps.googleusercontent.com",
"project_id":"<projectname>","auth_uri":"https://accounts.google.com/o/oauth2/auth",
"token_uri":"https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs",
"client_secret":"<secret key>",
"redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}}
Je ne sais pas ce que je suis absent en elle. Appréciez toute aide sur ce problème.
Qu'est-ce qui ne va pas dans mon code? – Shailendra