我正在使用Tweepy
通过推特ID从Twitter API收集推文
我试图读取一个充满ID的文件,从对话流中获取之前的推文,然后将该推文及其作者的屏幕名称等存储在文本文件中。一些推文已被删除或用户的个人资料已设置为私人,在这种情况下,我想忽略该推文并转到下一个。但是,出于某种原因,我没有收集所有可访问的推文。它存储的所有推文中有3/4是非私有且尚未删除的。任何想法为什么它没有抓住一切?
提前致谢。
def getTweet(tweetID, tweetObj, callTweetObj, i):
tweet = callTweetObj.text.encode("utf8")
callUserName = callTweetObj.user.screen_name
callTweetID = tweetObj.in_reply_to_status_id_str
with open("call_tweets.txt", "a") as calltweets:
output = (callTweetObj.text.encode('utf-8')+ "\t" + callTweetID + "\t" + tweetID)
calltweets.write(output)
print output
with open("callauthors.txt", "a") as callauthors:
cauthors = (callUserName+ "\t" + "\t" + callTweetID + "\n")
callauthors.write(cauthors)
with open("callIDs.txt", "a") as callIDs:
callIDs.write(callTweetID + "\n")
with open("newResponseIDs.txt", "a") as responseIDs:
responseIDs.write(tweetID)
count = 0
file = "Response_IDs.txt"
with open(file, 'r+') as f:
lines = f.readlines()
for i in range(0, len(lines)):
tweetID = lines[i]
sleep(5)
try:
tweetObj = api.get_status(tweetID)
callTweetID = tweetObj.in_reply_to_status_id_str
callTweetObj = api.get_status(callTweetID)
getTweet(tweetID, tweetObj, callTweetObj, i)
count = count+1
print count
except:
pass
答案 0 :(得分:0)
您尚未指定有关从api.get_status
返回的回复的信息,因此很难发现错误是什么。
但是,您可能已达到statuses/show/:id
请求的费率限制。 API
指定此请求仅限于180个窗口请求。
您可以使用Tweepy
来致电application/rate_limit_status
:
response = api.rate_limit_status()
remaining = response['resources']['statuses']['/statuses/show/:id']['remaining']
assert remaining > 0