本文整理汇总了Python中TwitterAPI.TwitterOAuth类的典型用法代码示例。如果您正苦于以下问题:Python TwitterOAuth类的具体用法?Python TwitterOAuth怎么用?Python TwitterOAuth使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TwitterOAuth类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_async
def run_async(self):
auth = TwitterOAuth.read_file_object(self.wrapper.getFileObject(__file__, "TwitterAPI/credentials.txt"))
api = TwitterAPI(auth.consumer_key, auth.consumer_secret, auth.access_token_key, auth.access_token_secret)
# list of user id to follow (by Nazli)
""" '@StiftenAGF','@jpaarhus','#Aarhus','@AarhusKultur','@smagaarhus','@AarhusNyheder','@AarhusPortaldk',
'@Aarhus2017','@OpenDataAarhus', '@aarhusupdate','@AskVest','@SundhedOgOmsorg','@ArhusVejr','@aarhus_ints',
'@AGFFANdk','@AarhusCykelby','@VisitAarhus','@larshaahr' """
users = ['3601200017', '3370065087', '3330970365', '2911388001', '2706568231',
'2647614595', '2201213730', '1324132976', '1065597596', '816850003', '763614246',
'210987829', '159110346', '112585923', '77749562', '38227253', '36040150']
# list of terms to track
tracks = ['#Aarhus']
print "TAA ready."
try:
r = api.request('statuses/filter', {'locations': self.location, 'follow': ','.join(users), 'track': ','.join(tracks)})
except:
print r.text
for item in r:
self.tweet = item
# print item
self.wrapper.update()
if self.abort.is_set():
break
示例2: init_twitter_api
def init_twitter_api(self):
o = TwitterOAuth.read_file("credentials.txt")
api = TwitterAPI(o.consumer_key,
o.consumer_secret,
o.access_token_key,
o.access_token_secret)
return api
示例3: getAppObject
def getAppObject(self):
if self.globalAppObj is None:
# Using OAuth1...
o = TwitterOAuth.read_file()
self.globalAppObj = TwitterAPI(o.consumer_key, o.consumer_secret, o.access_token_key, o.access_token_secret)
return self.globalAppObj
示例4: init_api
def init_api(credentials_file):
"""Initialize a connection to Twitter.
Arguments:
credentials_file -- A file with Twitter developer credentials.
Return an authenticated instance of TwitterAPI.
"""
auth = TwitterOAuth.read_file(credentials_file)
api = TwitterAPI(auth.consumer_key, auth.consumer_secret, auth.access_token_key, auth.access_token_secret)
return api
示例5: main
def main():
#Specify time to run script
EndDate='2013-11-30'
#loop to change filenames after day change
while str(date.today())!=EndDate:
dte=str(date.today())
# SAVE YOUR APPLICATION CREDENTIALS IN credentials.txt.
o = TwitterOAuth.read_file('credentials.txt')
api = TwitterAPI(o.consumer_key, o.consumer_secret, o.access_token_key, o.access_token_secret)
#see if authentications was successful
r = api.request('account/verify_credentials')
print(r.text)
#open timestamped file to store JSON tweets in:
d=date.today()
d=str(d)
filename=d+"_tweets_thanksgiving_blackfriday"
file_twts= codecs.open(filename,"ab",encoding="utf-8")
#stream tweets with a given keyword and store it in a file
#given using statuses/filter and using track : text terms seperated with , are regarded as or and those seperated by whtespace are regarded as and
try :
for item in api.request('statuses/filter', {'track':'thanksgiving, black friday, christmas, new year'}):
#print(item)
#indent to put on new lne indent=2
item=convert_reduced_json(item)
json.dump(item,file_twts)
file_twts.write('\n')
if str(date.today())!=dte:
break
file_twts.close()
except Exception as e:
print(e)
示例6: MongoClient
parser.add_argument('-endpoint', metavar='ENDPOINT', type=str, help='Twitter endpoint')
parser.add_argument('-parameters', metavar='NAME_VALUE', type=str, help='parameter NAME=VALUE', nargs='+')
parser.add_argument('-fields', metavar='FIELD', type=str, help='print a top-level field in the json response', nargs='+')
args = parser.parse_args()
try:
client = MongoClient('localhost', 27017)
db = client['devtweets']
tweets = db.tweets
except Exception as e:
print('*** STOPPED %s' % str(e))
try:
params = to_dict(args.parameters)
oauth = TwitterOAuth.read_file('./credentials.txt')
api = TwitterAPI(oauth.consumer_key, oauth.consumer_secret, oauth.access_token_key, oauth.access_token_secret)
"""response = api.request('statuses/filter', {'locations':'-102.878723,21.659981,-101.997757,22.473779'})"""
#response = api.request('search/tweets', {'q':'Aguascalientes 4sq com, ags 4sq com', 'count': 450})
lastTweet = tweets.find({}).sort('id', -1).limit(1)
str_lastTweetId = str(lastTweet[0]["id"])
pager = TwitterRestPager(api, 'search/tweets', {'q':'Aguascalientes 4sq com, ags 4sq com', 'count':100, 'since_id': str_lastTweetId})
#for item in response.get_iterator():
for item in pager.get_iterator(10):
print item
tweets.insert(item)
#print ('\n' % pager.get_rest_quota())
except KeyboardInterrupt:
print('\nTerminated by user')
示例7: print
if item['code'] == 131:
continue # ignore internal server error
elif item['code'] == 88:
print('Suspend search until %s' % search.get_quota()['reset'])
raise Exception('Message from twiter: %s' % item['message'])
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Search tweet history.')
parser.add_argument('-location', type=str, help='limit tweets to a place')
parser.add_argument('-oauth', metavar='FILENAME', type=str, help='read OAuth credentials from file')
parser.add_argument('-radius', type=float, help='distance from "location" in km')
parser.add_argument('words', metavar='W', type=str, nargs='+', help='word(s) to search')
args = parser.parse_args()
oauth = TwitterOAuth.read_file(args.oauth)
api = TwitterAPI(oauth.consumer_key, oauth.consumer_secret, oauth.access_token_key, oauth.access_token_secret)
try:
if args.location:
lat, lng, radius = GEO.get_region_circle(args.location)
print('Google found region at %f,%f with a radius of %s km' % (lat, lng, radius))
if args.radius:
radius = args.radius
region = (lat, lng, radius)
else:
region = None
search_tweets(api, args.words, region)
except KeyboardInterrupt:
print('\nTerminated by user\n')
except Exception as e:
示例8: TwitterAPI
target_csv.writeheader()
target_csv.writerows(data_lst)
target.close()
#fieldnames = ['tweet_date', 'tweet_id', 'tweet_date',
# dict_temp['tweet_id'] = item['id_str']
# dict_temp['tweet_date'] = item['created_at']
# dict_temp['user_name'] = item['user']['name']
# dict_temp['user_screen_name'] = item['user']['screen_name']
# dict_temp['tweet_text'] = item['text']
return
#############################################################################################################################################################
#############################################################################################################################################################
# SAVE YOUR APPLICATION CREDENTIALS IN TwitterAPI/credentials.txt.
o = TwitterOAuth.read_file()
api = TwitterAPI(o.consumer_key, o.consumer_secret, o.access_token_key, o.access_token_secret)
try:
if TEST_NUMBER == 0:
# VERIFY YOUR CREDS
r = api.request('account/verify_credentials')
print(r.text)
if TEST_NUMBER == 1:
# POST A TWEET
r = api.request('statuses/update', {'status':'the time is now %s' % datetime.now()})
示例9: TwitterAPI
#!/usr/bin/python3
# -*- encoding: utf-8 -*-
from TwitterAPI import TwitterAPI, TwitterOAuth, TwitterRestPager
import html, sys
o = TwitterOAuth.read_file('credentials.txt')
api = TwitterAPI(
o.consumer_key,
o.consumer_secret,
o.access_token_key,
o.access_token_secret)
示例10: setUp
def setUp(self):
"""Read credentials from TwitterAPI/credentials.txt. You
must copy your credentials into this text file.
"""
self.oa = TwitterOAuth.read_file()