I need help with my script uploading files to google drive
i have tried to read some modules like LWP::Authen::OAuth2, and many examples on internet but they all pointing out to 'URL for user to go to to start the process in browser', but for me am using this script in server as a background process
Anyone who can help i really appreciate
#!/usr/bin/perl - wT
use strict;
use warnings;
use LWP::UserAgent;
use LWP::Authen::OAuth2;
my $ua = LWP::UserAgent->new;
my $oauth2 = LWP::Authen::OAuth2->new(
client_id => 'client_id',
client_secret => 'client_secret',
site => 'https://accounts.google.com/o/oauth2/token',
+ # Token endpoint
authorize_url => 'https://accounts.google.com/o/oauth2/auth',
+# Authorization endpoint
redirect_uri => 'my_url_used_in_google_console_when_creating_
+client_id_and_client_secret',
);
# Use the access token to make API requests
$ua->default_header( 'Authorization' => 'Bearer ' . $oauth2->acces
+s_token );
my $url = 'https://www.googleapis.com/upload/drive/v3/files';
my $metadata = {
name => '/var/www/.../filename.sql', # Path to file in server
mimeType => 'application/txt',
};
my $response = $ua->post(
$url,
'Authorization' => 'Bearer ' . $oauth2->access_token,
'Content-Type' => 'application/json; charset=UTF-8',
'X-Upload-Content-Type' => 'application/txt',
Content => encode_json($metadata),
);
if ($response->is_success) {
print $res->decoded_content;
} else {
print $response->decoded_content;
print $response->status_line, "n";
}