[英]Error on getting user id from twitter using tweepy?
my code 我的密码
#!/usr/bin/python
import tweepy
import csv #Import csv
auth = tweepy.auth.OAuthHandler('XXXXXX', 'XXXXXXX')
auth.set_access_token('XXX-XXX', 'XXX')
api = tweepy.API(auth)
# Open/create a file to append data to
csvFile = open('result.csv', 'a')
#Use csv writer
csvWriter = csv.writer(csvFile)
for tweet in tweepy.Cursor(api.search,
q = "google",
since = "2014-02-14",
until = "2014-02-15",
lang = "en").items():
# Write a row to the CSV file. I use encode UTF-8
csvWriter.writerow([tweet.created_at,tweet.user, tweet.text.encode('utf-8')])
print tweet.created_at, tweet.text
csvFile.close()
Here I am unable to get user_id in the output. 在这里,我无法在输出中获取user_id。 the output is 输出是
2018-04-24 10:54:34 RT @BoldContentTV: Very excited to debut our first video for @StylistMagazine and . 2018-04-24 10:54:34 RT @BoldContentTV:很高兴为@StylistMagazine和推出我们的第一个视频。 Featuring the talented @ericafmstyle, #Fashi… 拥有才华横溢的@ ericafmstyle,#Fashi…
what is the reason? 是什么原因? and how can I get the user id? 以及如何获取用户ID? I want three aspects date/userid/text. 我想要三个方面的日期/用户名/文本。
You can get, 你可以得到,
username : tweet.user.screen_name
用户名: tweet.user.screen_name
text as : tweet.text
文字为: tweet.text
created_at : tweet.created_at
created_at: tweet.created_at
sample code: 样例代码:
In [33]: import tweepy
In [34]: auth = tweepy.OAuthHandler('', '')
In [35]: auth.set_access_token('', '')
In [36]: api = tweepy.API(auth)
In [37]: for tweet in tweepy.Cursor(api.search, q = "nishant").items(5):
...: print tweet.user.screen_name , tweet.text, tweet.created_at
...:
GuruInAJeans RT @periferrydotcom: Shaina's story is all about courage and the will to achieve.
it shows how patience can go a long way.
Full Story: htt… 2018-04-24 13:02:42
bajjiladeva @ts_nishant @KTRTRS neku ikkada first nene chepta bro inauguration date .. 2018-04-24 12:57:37
ts_nishant Don’t @KTRTRS <twitter short url> 2018-04-24 12:55:43
ts_nishant When @KTRTRS ?? <twitter short url> 2018-04-24 12:55:13
parivesh100 Nishant Shah on the invisible environmental costs that the digital age has brought - <twitter short url> 2018-04-24 12:47:56
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.