Method for controlling the authorization type used?
mr-devs opened this issue · 3 comments
I copied and pasted the below from the documentation that I just created a PR for (#14)...
As you can see in the second method below, if we want to manually control which authorization type we use when making queries, we have to play with the OsomeTweet._use_bearer_token
field (or parameter, or w/e it's called). That being said, you can see in the WARNING (at the bottom of the message) that you can set this to whatever you want and, if you don't set it correctly, it will break the class.
Would it be valuable to create a method which controls this - ensuring the user only passes in True
or False
? I am happy to do this, just wanted to make sure you guys agreed this was needed.
Let me know whenever. Thanks.
Controlling which authorization type you'd like to use
As mentioned above, osometweet
defaults to OAuth 2.0 Bearer Token authorization. If you'd like to use OAuth 1.0a authorization you can do that in two ways.
- Don't provide the
OsomeTweet
class yourbearer_token
osometweet
needs yourbearer_token
for OAuth 2.0 Bearer Token authorization. Thus, if you do not provide this token,osometweet
will look for yourbearer_token
- not find it - and then only use your user context Twitter keys/tokens (i.e.api_key
,api_key_secret
,access_token
,access_token_secret
) from then on. For example, simply initialize theOsomeTweet
class like this...
from osometweet.api import OsomeTweet
api_key = "YOUR_TWITTER_API_KEY"
api_key_secret = "YOUR_TWITTER_API_KEY_SECRET"
access_token = "YOUR_TWITTER_ACCESS_TOKEN"
access_token_secret = "YOUR_TWITTER_ACCESS_TOKEN_SECRET"
ot = OsomeTweet(
api_key = api_key,
api_key_secret = api_key_secret,
access_token = access_token,
access_token_secret = access_token_secret
)
- Manually
- Perhaps you have a more complicated script and you'd like to switch which authorization
osometweet
uses for different methods. You can manually do this by controlling whatosometweet
does withOsomeTweet._use_bearer_token
(boolean). For example:
- Perhaps you have a more complicated script and you'd like to switch which authorization
from osometweet.api import OsomeTweet
api_key = "YOUR_TWITTER_API_KEY"
api_key_secret = "YOUR_TWITTER_API_KEY_SECRET"
access_token = "YOUR_TWITTER_ACCESS_TOKEN"
access_token_secret = "YOUR_TWITTER_ACCESS_TOKEN_SECRET"
bearer_token = "YOUR_TWITTER_BEARER_TOKEN"
ot = OsomeTweet(
api_key = api_key,
api_key_secret = api_key_secret,
access_token = access_token,
access_token_secret = access_token_secret,
bearer_token = bearer_token
)
# The below line tells osometweet to NOT use the bearer_token even though it has been provided
ot._use_bearer_token = False # <-------
# You can then switch it back with...
ot._use_bearer_token = True
WARNING:
OsomeTweet._use_bearer_token
can only be set to the boolean valuesTrue
orFalse
- any other value will break the class.
Would it be valuable to create a method which controls this - ensuring the user only passes in True or False? I am happy to do this, just wanted to make sure you guys agreed this was needed.
I like this!
I was actually thinking about creating a standalone OAuth class just to handle this like tweepy. This way we can decouple OSoMeTweet and oauth. The code would be easier to maintain.
Under this structure, we can many have two OAuth classes for two versions respectively. This way it would be very clear what version of OAuth the user is using.
I think that having two OAuth classes is probably the best idea, good thinking.
Not sure if you want to close this issue and start a new one or just use this one - fine with me either way. 👍