Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #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 };
Add Comment
Please, Sign In to add comment