Twitter Streaming API connection times out after 3 hours

582 Views Asked by At

I'm trying to use the Twitter Streaming API to collect data from Twitter.

below is my code in r

filterStream(oauth=my_oauth, 
         timeout = 0, track = keyword,
         file.name = "tweets.json") 
       tweetsdf = parseTweets("tweets.json", simplify = TRUE) 
       View(tweetsdf)

You can see that i have set the timeout to 0 which should mean that the connection is always on. but what i'm finding is that my connection is dropped after just under 3 hours.

1

There are 1 best solutions below

1
On

You are going to want the connection to timeout because Twitter will drop the connection when there is no activity after 90 seconds. Put your code inside a try block inside a while loop. That way you can reconnect when your connection drops.