geduldig / TwitterAPI

Minimal python wrapper for Twitter's REST and Streaming APIs
939 stars 263 forks source link

Add bearer_token as optional param #155

Closed dylancaponi closed 3 years ago

dylancaponi commented 3 years ago

Bearer Token is available in the twitter developer portal and does not change unless regenerated or revoked.

My understanding is that TwitterAPI currently gets that here.

However, I would like to add an optional bearer_token param to the API instantiation in order to reduce the number of calls being made to TwitterAPI and thus reduce the number of failed requests.

Please let me know if you have advice on how to approach this.

image

geduldig commented 3 years ago

What is the scenario where you are making numerous calls to Twitter for the bearer token?

dylancaponi commented 3 years ago

Well, I think it's called every time that TwitterAPI is instantiated with:

api = TwitterAPI(...)

So I'm not making numerous calls during a single run, but if I run a single job every 15 minutes that's 96 extra calls to Twitter per day that I don't need to be making. One potential source of failure when it could just be loaded from local secrets.

A recent example of why we try to reduce calls anywhere possible: We had an issue with Google where we were calling get_bucket which actually queries the API to see if the bucket exists, instead of just Bucket to instantiate the bucket by name and after removing that one extra call we cut our 503, 504 errors in half.

geduldig commented 3 years ago

With is feature, I think, the number of requests you will be reducing is trivial. The number of errors you will be reducing, in my experience, will also be trivial.

However, adding a bearer_token param should not be a problem. Check back in about a week.

dylancaponi commented 3 years ago

I agree this is lowest priority and realized that many fields still require oauth1.0a which does not use bearer token.

geduldig commented 3 years ago

Closing until there is a strong case for this enhancement.