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.
Related
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.
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.
When using Tweepy search API to crawl tweets, how to restricts the search scope to a specific user and a specific language?
The effect is just like advanced searching:
MH370 lang:en from:cnn
Any hints?
You can use
tweepy.API.search(q[, lang][, locale][, rpp][, page][, since_id][, geocode][, show_user])
with parameters lang="en",show_user=True and add from:cnn to your query string. See also the API Reference.
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
I'm attempting to get the statuses of followed users only using the Python Twitter library. It works fine for the 'everyone' stream:
from twitter.stream import TwitterStream
from twitter.oauth import OAuth
from twitter.util import printNicely
stream = TwitterStream(
auth=OAuth(
acc_key, acc_secret,
con_key, con_secret),
domain="userstream.twitter.com",
api_version='1',
secure=True)
print stream.statuses.sample()
tweet_iter = stream.statuses.sample()
for tweet in tweet_iter:
if tweet.get('text'):
printNicely(tweet['text'])
But I want to restrict the output to users I follow only. As far as I can tell from the docs, sample() gives me everything, but I can't tell whether there's a filter() method. Should I be using a different library? I've been using Tweepy for non-streaming Twitter tasks.
Actually, twython doesn't support support the userstream live stream. See here. There doesn't seem to be much activity in its user group, either.
I recommend twython for a Python Twitter library. It is regularly maintained, a useful property considering how often Twitter changes its API.
EDIT: See tweetstream for a simple streaming API implementation which as filtering capabilities.