So I am doing fairly trivial task of retrieving tweets from a particular user. What I really want to do is to count how many times each of his tweets have been retweeted. I have looked at python's tweepy's API, and I have not been able to find a clear answer. Is there a way to do this in python?
tweepy, might not have method for every endpoint in the twitter API.
tweepy should allow you to call an arbitrary endpoint, though. When in doubt, you can check out the official twitter API to see what is offered.
https://dev.twitter.com/docs/api/1.1
It appears that you might only be able to get 100 retweets for a given tweet_id
https://dev.twitter.com/docs/api/1.1/get/statuses/retweets/%3Aid
https://dev.twitter.com/docs/api/1.1/get/statuses/retweeters/ids
Related
I'm trying to pull tweets from a user's timeline in real-time. I then want to do some analysis on those tweets. Having read the docs it looks like I will need to use tweepy.Stream for this use case. I've done the following:
stream.filter(follow='25073877')
But Twitter's filter API states the following:
Tweets created by the user.
Tweets which are retweeted by the user.
Replies to any Tweet created by the user.
Retweets of any Tweet created by the user.
Manual replies, created without pressing a reply
button (e.g. “#twitterapi I agree”).
It seems that this will return a huge volume of tweets that aren't relevant to my use case. Do I have to use this approach and then filter by screen name to get only tweets by the real user? This doesn't seem right at all.
The alternative seems to be the api.user_timeline class but that isn't a streaming API. Do I therefore use this API and hit it every second? I can't seem to find suitable examples of how best to accomplish my use case.
Yes, you'll need to filter either by screen_name or maybe you can check if it's a retweet or not.
I wouldn't recommend the second approach since you'll be getting an even bigger amount of tweets since you'll have to filter out the tweets you already received in previous requests plus you may hit the API querying limits if you don't time ti properly.
That's the signature of the filter function:
def filter(self, follow=None, track=None, is_async=False, locations=None,
stall_warnings=False, languages=None, encoding='utf8', filter_level=None)
Which maps to this Twitter API request.
And here the explanation of the parameters.
I've been looking on the internet for a way to follow a random user on Twitter in a while loop. While I've seen the loop you can use to find tweets (and then do something), how do you find users?
Tweepy library has an API search_users(q) to retrieve the first 1000 matches based on the query 'q'.
API Documentation
I want to setup a bot, which will read tweets from a twitter user and store. I can find several examples on search for particular key words, post ID etc.
Can any one recommend which api call is required for monitoring one particular user?
use tweepy for data mining from twitter https://github.com/tweepy/tweepy
The Twitter API call you would use is statuses/user_timeline. The documentation is here.
Some python examples to get you started with using Twitter are here.
I have a requirement to get all the tweets from the specific trend in twitter.
Ex: api.get_all_tweets(trend="ABCD")
How can I achieve this with tweepy?
There is no way to be guaranteed to capture all tweets. Twitter reserves the right to send you whatever they feel like. For something that is tweeted about infrequently like #upsidedownwalrus you'd probably get all of them, but for something that is a trending topic, you will only ever receive a sample.
The Twitter API has limits on what you can retrieve. If you require a census of posted Tweets, you'll need to pay for a service that provides such, but they are few and far between as they need to actively respect deletions.
I'm trying to retrieve all the tweets from a user in python with this lib.
The method provided in python-twitter to do this is defined as :
def GetUserTimeline(self,
user_id=None,
screen_name=None,
since_id=None,
max_id=None,
count=None,
include_rts=None,
trim_user=None,
exclude_replies=None):
Though if the count is limited to 200.
Documentation:
count:
Specifies the number of statuses to retrieve. May not be
greater than 200. [Optional]
My question now is: Is it possible to retrieve all the tweets from a user with this lib ? And is there an alternative solution ?
Short answer: no.
Twitter API explicitly says that you cannot retrieve more then 200 tweets from a user per request so this is not a limitation of this particular library you're using but a limitation imposed by Twitter. But keep in mind that this is per request, if you will send multiple requests you can get up to 3200 tweets in total. But this still means that you can't get all tweets, only 3200.
Here is official Twitter API statuses/user_timeline endpoint documentation.