· 7 years ago · Jan 26, 2018, 01:22 PM
1from Twython import Twython
2
3TWITTER_APP_KEY = 'xxxxx' #supply the appropriate value
4TWITTER_APP_KEY_SECRET = 'xxxxx'
5TWITTER_ACCESS_TOKEN = 'xxxxxx'
6TWITTER_ACCESS_TOKEN_SECRET = 'xxxxx'
7
8t = Twython(app_key=TWITTER_APP_KEY,
9 app_secret=TWITTER_APP_KEY_SECRET,
10 oauth_token=TWITTER_ACCESS_TOKEN,
11 oauth_token_secret=TWITTER_ACCESS_TOKEN_SECRET)
12
13search = t.search(q='#omg', #**supply whatever query you want here**
14 count=100)
15
16tweets = search['statuses']
17
18for tweet in tweets:
19 print tweet['id_str'], 'n', tweet['text'], 'nnn'
20
21from twython import Twython
22twitter = Twython()
23search_results = twitter.search(q="#somehashtag", rpp="50")
24
25for tweet in search_results["results"]:
26 print "Tweet from @%s Date: %s" % (tweet['from_user'].encode('utf-8'),tweet['created_at'])
27 print tweet['text'].encode('utf-8'),"n"
28
29from twython import Twython, TwythonError
30
31# Requires Authentication as of Twitter API v1.1
32twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
33try:
34 search_results = twitter.search(q='WebsDotCom', count=50)
35except TwythonError as e:
36 print e
37
38for tweet in search_results['statuses']:
39 print 'Tweet from @%s Date: %s' % (tweet['user']['screen_nam
40 e'].encode('utf-8'),
41 tweet['created_at'])
42print tweet['text'].encode('utf-8'), 'n'