
Untitled
By: a guest on
Aug 21st, 2012 | syntax:
None | size: 0.75 KB | hits: 16 | expires: Never
#load token if previously saved
if( my $data = read_file( $tokenfile ) ) {
$self->{token} = $data;
}
#instanciate api with token_or_undef
$self->{api} = Net::OAuth2::Client->new(
$self->{client_id},
$self->{client_secret},
site => $self->{site},
authorize_path => $self->{authorize_path},
access_token_path => $self->{access_token_path},
access_token_method => $self->{access_token_method},
access_token_param => $self->{access_token_param},
scope => $self->{scope},
)->web_server(
redirect_uri => $self->{callback}
)->get_access_token(
%{$self->{token}}
);
#...
# uses of $self->{api}->access_token() automically refreh it if needed
#and finally save the token
write_file $tokenfile => { $self->{api}->save };