#!/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->access_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"; }