This code in Perl was working for years and now my Spreadsheets logins failed, when I logged into my account I noticed switch to a new Drive version. Probably some authentication methods deprecated?
my $auth = Net::Google::AuthSub->new;
my $response = $auth->login('LOGIN@gmail.com', 'PASS');
if ($response->is_success) {
print "Hurrah! Logged in\n";
} else {
die "Login failed: ".$response->error."\n";
}
The result is:
Login failed:
And the code:
use Net::Google::Spreadsheets;
my $service = Net::Google::Spreadsheets->new(
username => 'LOGIN@gmail.com',
password => 'PASS'
);
The result is:
Net::Google::AuthSub login failed at /usr/local/share/perl/5.18.2/Net/Google/Spreadsheets.pm line 42.
As suggested somewhere I tried to skip SSL certificate checking with:
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
but this doesn't help too. What can I do to make it work? Thanks.
That code above absolutely would not work for me. After looking around for several hours, reading the documentation and trying different things I finally ran across some code that worked. 90% of it is the same but it was the missing 10% and the accompanying explanations that made all the difference.
http://pastebin.com/8LeMyLW4
(Originally from this Stack Overflow post: Authenticating in a Google sheets application)
Thanks for this - very helpful. One addition is that the code in the original poster's answer will generate a token that expires in an hour. If you want to keep using it, you need to be sure to formulate the initial request so that it generates not only the access token, but also the refresh token. To get this, change the initial
to
Then the returned token will have the necessary refresh_token included.
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:
Save and restore token session example found at https://gist.github.com/hexaddikt