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"; }

In reply to google drive by frank1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.