I am trying to pull tweets using before_id and max_id. The problem with_id is that it correctly prints all the tweets in my eclipse console, but when I try to save it line by line as a csv file, it does not return me all the tweets. I tried to run it 4-5 times, but every time I get a different number of tweets. The problem with max_id is that it does not work. My code looks like this, and tracing is included after the code (for the from_id parameter, I just replace max_id only with the from_id function)
import tweepy
import csv
from datetime import *
import time
access_token = ''
access_secret = ''
consumer_key = ''
consumer_secret = ''
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
api = tweepy.API(auth)
csvFile = open('a.csv','a')
csvWriter = csv.writer(csvFile, delimiter=',')
i = 1
tweets = tweepy.Cursor(api.user_timeline, id = '', max_id = 510064587115225000).items()
while True:
try:
for tweet in tweets:
csvWriter.writerow([i, tweet.retweet_count, tweet.favorite_count, str(tweet.id), tweet.created_at.hour,tweet.created_at.minute,tweet.created_at.weekday(),tweet.created_at.day,tweet.created_at.month,tweet.created_at.year,tweet.created_at ,tweet.text.encode('utf8'), tweet.user.id, tweet.geo, tweet.in_reply_to_user_id, tweet.in_reply_to_status_id_str, tweet.place, tweet.retweeted, tweet.truncated, tweet.source])
print i
i+=1
except tweepy.TweepError:
time.sleep(60 * 15)
continue
except StopIteration:
break
csvFile.close()
This is my trace for max_id (since from_id does not cause any errors)
for tweet in tweets:
File "C:\Python27\lib\site-packages\tweepy\cursor.py", line 181, in next
self.current_page = self.page_iterator.next()
File "C:\Python27\lib\site-packages\tweepy\cursor.py", line 99, in next
data = self.method(max_id=self.max_id, parser=RawParser(), *self.args, **self.kargs)
TypeError: _call() got multiple values for keyword argument 'max_id'
, csv, tweet_ids . . tweet_id, for_id max_id, .