I have to answer my question as I was happy to find a solution. Google changed their authentication algorithm, so we have to use OAuth 2.0.
You will need to create Credentials at: https://console.developers.google.com/
APIs & auth -> Credentials -> OAuth -> Client ID -> Installed application -> Other
and enable your API i.e.: APIs & auth -> APIs -> Google Apps APIs > Drive API
The following code works fine:
use Net::Google::DataAPI::Auth::OAuth2;
use Net::Google::Spreadsheets;
use Storable; #to save and restore token for future use
my $oauth2 = Net::Google::DataAPI::Auth::OAuth2->new(
client_id => 'ID.apps.googleusercontent.com',
client_secret => 'SECRET',
scope => ['http://spreadsheets.google.com/feeds/'],
);
#you can skip URL if you have your token saved and continue from RESTORE label
my $url = $oauth2->authorize_url();
#you will need to put code here and receive token
print "OAuth URL, get code: $url
";
use Term::Prompt;
my $code = prompt('x', 'paste the code: ', '', '');
my $token = $oauth2->get_access_token($code) or die;
#save token for future use
my $session = $token->session_freeze;
store($session, 'google_spreadsheet.session');
RESTORE:
my $session = retrieve('google_spreadsheet.session');
my $restored_token = Net::OAuth2::AccessToken->session_thaw($session,
auto_refresh => 1,
profile => $oauth2->oauth2_webserver,
);
$oauth2->access_token($restored_token);
my $service = Net::Google::Spreadsheets->new(auth => $oauth2);
# and then as before..
Save and restore token session example found at https://gist.github.com/hexaddikt
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…