I am trying to pull the Category/Topic of Tweets for a school project.
I am not seeing it as one of the keys in public_tweets (below), was wondering if it was located within a variable somewhere else? Thanks!
Example of a Twitter Topic/Category (would like to pull the “Lebron James” label):
Topics are known as “context annotations” in the Twitter API, and are only available in v2. The Tweet data you have here is from v1.1. You’ll need to update the way you are accessing the API and add parameters to get Tweet expansions and fields for context annotations.
Related
I'm trying to retrieve viral tweets for an academic project using the Twitter API v2. There is a Topic on Twitter called "viral tweets" which is perfect for what I want.
It has id 1284234742661963776 so my thoughts was to query using context annotations. However there is no entity related to viral tweets on the API. I've tried to input this entity id using context id 131 which corresponds to the Twitter Unified Taxonomy, but got nothing. Did someone manage to retrieve them? Are not all topics on Twitter available on the API?
Here is an example of the code I used
Not all topics available on Twitter are part of the context annotations provided via the Twitter API. You can read more about this and see an example in this answer.
I'm using the python library tweepy in order to extract data from the twitter api v2.
The api also possesses the option to provide tweet annotations, which are basically categorization of certain elements used in the tweet. (The endpoint and documentation of this is available at: https://developer.twitter.com/en/docs/twitter-api/annotations/overview).
My question would be if there is a way to call this endpoint via tweepy? Or is there another way to access the automatic categorization of words using tweepy?
From the tweepy documentations:
tweepy.Tweet.context_annotations
should give you the infos you want.
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 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 need to retrieve specific data from twitter.
I'd like to get all the responses tweets received by a specific user (which is not the authenticating user of the program). Is there a way to achieve this? Right now I'm thinking about using the search function and see if the 'in_reply_to_user_id_str' matches the id of the user I want.
But this means that I need to filter a lot of data to find the one I want
Edit: I'm using the Python-Twitter-Tools
If it is the authenticating user, you can directly get the response tweets using the 'mentions timeline'. As the user is not the authenticating user, you have two options here.
Streaming API
Use the filter endpoint along with the 'follow' parameter. Pass the required 'user_id' to the follow paramenter and it will return the followings. You will have to check the 'in_reply_to_user_id_str' in order to isolate the replies(responses).
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.
Python-Twitter-Tools supports Streaming API. Streaming API is realtime and better than Search API considering the completeness.
Search API
Every response tweet contains the "#username" tag. You can searching using "#username" tag and then filter the tweets using 'in_reply_to_user_id_str' as you have mentioned.
Considering the two options, Streaming API will help you to get what you need easily and reliably.