python-twitter icon indicating copy to clipboard operation
python-twitter copied to clipboard

Example code of OAuth2 with public client temporary tokens

Open rdpickard opened this issue 2 years ago • 0 comments

Hi all,

Thanks for all the work on this module.

I have created an example of using the module with OAuth2 public clients. The example code is here in a gist.

The script itself will 'Unlike' all of a user's liked Tweets. So run as-is with caution.

The interesting bit is the WrappedPyTwitterAPI subclass of pytwitter.Api.

The example will handle a few things I did not see in other examples

  • capturing the OAuth2 callback from inside the app
  • refreshing access tokens that Public Client apps get when they expire
  • detecting errors that can be recovered from, such as Rate Limit exceeded and token expired.

Hope this is helpful.

rdpickard avatar Jan 17 '22 19:01 rdpickard