Skip to content

Instantly share code, notes, and snippets.

@hexaddikt
Last active December 24, 2015 03:38
Show Gist options
  • Select an option

  • Save hexaddikt/6738247 to your computer and use it in GitHub Desktop.

Select an option

Save hexaddikt/6738247 to your computer and use it in GitHub Desktop.
Shows how to load a session that was serialised earlier and reuse the refresh token for authentication.
#!/usr/bin/perl
use strict;
use warnings;
use v5.10;
use Net::Google::Spreadsheets;
use Net::Google::DataAPI::Auth::OAuth2;
use Net::OAuth2::AccessToken;
use Storable;
my $sessionfile="/<directory where the session was stored>/google_spreadsheet.session";
my $oauth2 = Net::Google::DataAPI::Auth::OAuth2->new(
client_id => '...',
client_secret => '...',
scope => [ 'http://spreadsheets.google.com/feeds/' ],
);
# deserialise the file so we can thaw the session and reuse the refresh token
my $session = retrieve($sessionfile);
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,
);
my $usage_spreadsheet = $service->spreadsheet(
{
key => '... spreadsheet key ...',
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment