1
votes

I am using Twitter's REST API V1.1 and I need to count the number of followers for a specific time period e.g I want to see how many users followed me from Feb to August 2013. And same for the favorites, retweets etc.

Any guidance you can provide to access this type of data?

Thanks

2
Your question is too open-ended for Stack Overflow, and the scope is too broad. People could give you many answers for "guidance". Stack Overflow questions need to be about specific problems that don't have multiple answers. Consider reframing your question as a problem around specific pieces of code. See this and this. - user456814
what you have tried ? - Sabyasachi Ghosh
I am now able to access the only retweets within the mentioned date by comparing dates. But the major issue is now to have number of followers within a mentioned time span. Twitter API V1.1 provides only a list of users' IDs. What to do in this case? - user3431704

2 Answers

1
votes

Gem

Since you're using Rails, I would recommend using the Twitter gem by sferik. This gem interfaces directly with the Twitter v1.1 API, and has all the hooks you require:

Followers - client.friends("username")

Favourites - not sure

Retweets - client.mentions_timeline

I'm not sure how to only return time-constrained formats for this gem. Failing a native ability to only pull the required data, you'll have to pull all the data & split for the required time period. However, this will very inefficient & expensive


JS

This is the most efficient & "natural" way to access Twitter data in Rails. Failing that, there is a JS method called Twitterfetcher, which basically parases a Twitter Widget & allows you to display the content as required

1
votes

In addition to using the Gem provided in another answer, a solution to solving the number of users within a certain time span would be to first find your follower list. The gem must support this. After authentication, make the get request as such

GET followers/list

This will return a cursored collection of user objects for users following the specified user. Read more Here

The tricky part is the "created_at" field.. I'm not sure if this is a date of when the user created their twitter account, or the date of when the user started following you. You are most likely going to have to test this one for yourself, but I would start with reading through the twitter API documentation.