I have an application that uses Net::Google::Spreadsheets. It began to fail with authentication errors earlier this week. My understanding is that Google has deprecated some authentication methods, and that we are now to use OAuth2.
My application runs on a headless server, so I cannot use the three-legged OAuth2 solution shown in Net::Google::AuthSub login failed with new Google Drive version
I need to use two-legged authentication with a service account. I put together code to build the JWT, and obtain the access_token (as detailed in the Google developer documentation).
What I need some assistance with is the method I need to use to get Net::Google::Spreadsheets to make use of this access_token, or a method to do two-legged OAuth2 that works with this module.
If you have managed to create the access_token, then you should be able to get it into the right format for Net::Google::Spreadsheets by using it to create a new Net::OAuth2::AccessToken object, and then proceeding more or less as in the example you linked to in the other thread:
use Net::Google::Spreadsheets;
use Net::Google::DataAPI::Auth::OAuth2;
use Net::OAuth2::AccessToken;
my $oauth2 = Net::Google::DataAPI::Auth::OAuth2->new(
client_id => 'my_client_id.apps.googleusercontent.com',
client_secret => 'my secret',
scope => ['http://spreadsheets.google.com/feeds/'],
);
my $access_token = 'token you generate somehow';
my $token = Net::OAuth2::AccessToken->new(access_token => $access_token,
profile => $oauth2->oauth2_webserver,
token_type => 'Bearer',
);
$oauth2->access_token($token);
my $service = Net::Google::Spreadsheets->new(auth => $oauth2);
and then you can use the service from there. If you want to repeatedly use the same token, you'll need to get a refresh_token as well and include that, as well as setting auto_refresh, but if you're generating a new one each time, this should work.