Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 21st, 2012  |  syntax: None  |  size: 0.75 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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 };