Guest User

Untitled

a guest
Sep 23rd, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1.  
  2. #load token if previously saved
  3. if( my $data = read_file( $tokenfile ) ) {
  4. $self->{token} = $data;
  5. }
  6.  
  7. #instanciate api with token_or_undef
  8. $self->{api} = Net::OAuth2::Client->new(
  9. $self->{client_id},
  10. $self->{client_secret},
  11. site => $self->{site},
  12. authorize_path => $self->{authorize_path},
  13. access_token_path => $self->{access_token_path},
  14. access_token_method => $self->{access_token_method},
  15. access_token_param => $self->{access_token_param},
  16. scope => $self->{scope},
  17. )->web_server(
  18. redirect_uri => $self->{callback}
  19. )->get_access_token(
  20. %{$self->{token}}
  21. );
  22.  
  23. #...
  24. # uses of $self->{api}->access_token() automically refreh it if needed
  25.  
  26. #and finally save the token
  27. write_file $tokenfile => { $self->{api}->save };
Add Comment
Please, Sign In to add comment