Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def twitter_auth(params):
import webbrowser
if sys.version_info[0] >= 3:
from urllib.parse import parse_qsl
else:
from urlparse import parse_qsl
import oauth2 as oauth
consumer = oauth.Consumer(pct.consumer_key, pct.consumer_secret)
client = oauth.Client(consumer)
# step 1 - obtain a request token
resp, content = client.request(
'https://api.twitter.com/oauth/request_token', 'POST')
if resp['status'] != '200':
print('Failed to get request token. [%s]' % resp['status'])
return 1
if isinstance(content, bytes):
content = content.decode('utf-8')
request_token = dict(parse_qsl(content))
# step 2 - redirect the user
redirect_url = 'https://api.twitter.com/oauth/authorize?oauth_token=%s' % (
request_token['oauth_token'])
if not webbrowser.open(redirect_url, new=2, autoraise=0):
print('Please use a web browser to open the following URL')
print(redirect_url)
def __init__(self, key, secret, latitude, longitude):
logger.info('Using tweepy library')
auth = tweepy.OAuthHandler(pct.consumer_key, pct.consumer_secret)
auth.set_access_token(key, secret)
self.api = tweepy.API(auth)
if latitude is not None and longitude is not None:
self.kwargs = {'lat' : latitude, 'long' : longitude}
else:
self.kwargs = {}
def __init__(self, key, secret, latitude, longitude):
logger.info('Using tweepy library')
auth = tweepy.OAuthHandler(pct.consumer_key, pct.consumer_secret)
auth.set_access_token(key, secret)
self.api = tweepy.API(auth)
if latitude is not None and longitude is not None:
self.kwargs = {'lat' : latitude, 'long' : longitude}
else:
self.kwargs = {}
def TwitterAuth(params):
consumer = oauth.Consumer(Twitter.consumer_key, Twitter.consumer_secret)
client = oauth.Client(consumer)
# step 1 - obtain a request token
resp, content = client.request(
'https://api.twitter.com/oauth/request_token', 'POST')
if resp['status'] != '200':
print 'Failed to get request token. [%s]' % resp['status']
return 1
request_token = dict(urlparse.parse_qsl(content))
# step 2 - redirect the user
redirect_url = 'https://api.twitter.com/oauth/authorize?oauth_token=%s' % (
request_token['oauth_token'])
if not webbrowser.open(redirect_url, new=2, autoraise=0):
print 'Please use a web browser to open the following URL'
print redirect_url
pin = raw_input('Please enter the PIN shown in your web browser: ').strip()
# step 3 - convert the request token to an access token
def register(self):
import webbrowser
if sys.version_info[0] >= 3:
from urllib.parse import parse_qsl
else:
from urlparse import parse_qsl
import oauth2 as oauth
consumer = oauth.Consumer(pct.consumer_key, pct.consumer_secret)
client = oauth.Client(consumer)
# step 1 - obtain a request token
resp, content = client.request(
'https://api.twitter.com/oauth/request_token', 'POST')
if resp['status'] != '200':
print('Failed to get request token. [%s]' % resp['status'])
return
if isinstance(content, bytes):
content = content.decode('utf-8')
request_token = dict(parse_qsl(content))
# step 2 - redirect the user
redirect_url = 'https://api.twitter.com/oauth/authorize?oauth_token=%s' % (
request_token['oauth_token'])
if not webbrowser.open(redirect_url, new=2, autoraise=0):
print('Please use a web browser to open the following URL')
print(redirect_url)
def __init__(self, key, secret, latitude, longitude, timeout):
logger.info('Using python-twitter library')
self.api = twitter.Api(
consumer_key=pct.consumer_key,
consumer_secret=pct.consumer_secret,
access_token_key=key, access_token_secret=secret,
timeout=timeout)
if latitude is not None and longitude is not None:
self.kwargs = {'latitude' : latitude, 'longitude' : longitude,
'display_coordinates' : True}
else:
self.kwargs = {}
self.kwargs['verify_status_length'] = False
def __init__(self, key, secret, latitude, longitude, timeout):
logger.info('Using python-twitter library')
self.api = twitter.Api(
consumer_key=pct.consumer_key,
consumer_secret=pct.consumer_secret,
access_token_key=key, access_token_secret=secret,
timeout=timeout)
if latitude is not None and longitude is not None:
self.kwargs = {'latitude' : latitude, 'longitude' : longitude,
'display_coordinates' : True}
else:
self.kwargs = {}
self.kwargs['verify_status_length'] = False