Last active
December 24, 2015 03:38
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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