Rishikant181 / Rettiwt-API

A CLI tool and an API for fetching data from Twitter for free!
https://rishikant181.github.io/Rettiwt-API/
MIT License
363 stars 34 forks source link

Add authentication using guestToken manually #402

Closed vlatkoodrljin closed 9 months ago

vlatkoodrljin commented 9 months ago

Hi, great work on the library.

Currently for authentication, if apiKey is not provided guestToken is automatically created.

AuthCredential model from auth library has support for authentication with cookies and guestToken.

Please allow passing guestToken in Rettiwt instance as config, together with apiKey (automatic guest token generation then is not necesary).

In some cases is useful to have ability to change guest tokens manually.

Rishikant181 commented 9 months ago

Any examples of such a use case?

vlatkoodrljin commented 9 months ago

Guest authentication is specific Twitter type of authentication same like account authentication with cookie/apiKey.

We can fetch significant data from Twitter only using guest token, currently that's fact. (limited data, and not for all resources, but that's not important, it's still useful data)

Currently, from Rettiwt instance we cannot control which guest token will be used for making Twitter request.

For example, its useful to have your own separated list of guest tokens and rotate them for making user timeline requests to increase limit.

Currently, limit is 50reqs in 15mins authenticated only with guest token, generated once in the background before making first actual request.

Having pregenerated list of guest tokens give us more flexibility and bigger limits.

Other problem with current code is that we create request for generating guest token always in the background, before first actual request, without any control.

It's unexpected, slow and inefficient having that by default, without option for passing guestToken from outside. But if we create Rettiwt instance without guestToken that's fine.

To conclude, it would be useful to give option for passing of already generated guest token from top Rettiwt instance. We would control everything what is important and affect limits, have better separation of concerns and much cleaner code.

Logic for that is already in AuthCredential constructor, just need to pass that value from top level instance.

Tnx in advance Vlatko

Rishikant181 commented 9 months ago

Actually, currently, a new guest token is created for each request sent i.e, 1 unique guest token for 1 request. So it's already using different guest token for different requests, without being explicitly instructed to do so.

As you can see here, whenever a request is made without using any credentials to twitter account, the getGuestCredential() is called. This method generates a new guest token each time it is called, as can be seen here

It's unexpected, slow and inefficient having that by default, without option for passing guestToken from outside. But if we create Rettiwt instance without guestToken that's fine.

That's a fair point though, and I will be working on it in some time, approximately 2 weeks from now (owing to moving to a different city for my first job).