@@ -260,9 +260,8 @@ def __init__(self,
260260 "strongly advised to increase it above 16384"
261261 ))
262262
263- if consumer_key is None or consumer_secret is None or (
264- not application_only_auth
265- and (access_token_key is None or access_token_secret is None )):
263+ if not (all ([consumer_key , consumer_secret ])
264+ and (application_only_auth or all ([access_token_key , access_token_secret ]))):
266265 raise TwitterError ({'message' : "Missing oAuth Consumer Key or Access Token" })
267266
268267 self .SetCredentials (consumer_key , consumer_secret , access_token_key , access_token_secret ,
@@ -281,25 +280,25 @@ def __init__(self,
281280 requests_log .propagate = True
282281
283282 def GetAppOnlyAuthToken (self , consumer_key , consumer_secret ):
284- """
285- Generate a Bearer Token from consumer_key and consumer_secret
286- """
287- from urllib import quote_plus
288- import base64
289-
290- key = quote_plus (consumer_key )
291- secret = quote_plus (consumer_secret )
292- bearer_token = base64 .b64encode ('{}:{}' .format (key , secret ) )
293-
294- post_headers = {
295- 'Authorization' : 'Basic ' + bearer_token ,
296- 'Content-Type' : 'application/x-www-form-urlencoded;charset=UTF-8'
297- }
298- res = requests .post (url = 'https://api.twitter.com/oauth2/token' ,
299- data = {'grant_type' :'client_credentials' },
300- headers = post_headers )
301- bearer_creds = res .json ()
302- return bearer_creds
283+ """
284+ Generate a Bearer Token from consumer_key and consumer_secret
285+ """
286+ from urllib import quote_plus
287+ import base64
288+
289+ key = quote_plus (consumer_key )
290+ secret = quote_plus (consumer_secret )
291+ bearer_token = base64 .b64encode ('{}:{}' .format (key , secret ) )
292+
293+ post_headers = {
294+ 'Authorization' : 'Basic ' + bearer_token ,
295+ 'Content-Type' : 'application/x-www-form-urlencoded;charset=UTF-8'
296+ }
297+ res = requests .post (url = 'https://api.twitter.com/oauth2/token' ,
298+ data = {'grant_type' :'client_credentials' },
299+ headers = post_headers )
300+ bearer_creds = res .json ()
301+ return bearer_creds
303302
304303 def SetCredentials (self ,
305304 consumer_key ,
0 commit comments