Suppose that a twitter user has sent a tweet which has a specific tweet id. What is the best way to get n tweets from same user exactly before that specific tweet id using tweepy?
Any help will be appreciated.
Read the official Twitter documentation :
https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets.html
And use the parameter q with from:#user and count=10 where 10 is your "n" andmax_id=id where "id" is your tweet id.
And read the officiel tweepy documentation for the seach API.
We can fix bugs for you but won't code for you.
Related
I am using python package GetOldTweets3 to extract all tweets from a specific user between a specific timeframe. However, I only want the 'original' tweets, and no public replies or retweets the user makes.
Is there any possibility to do this with GetOldTweets3 or any way to expand the package?
import GetOldTweets3 as got
tweetCriteria =
got.manager.TweetCriteria().setUsername(username).setSince(startdate).setUntil(enddate)
tweets = got.manager.TweetManager.getTweets(tweetCriteria)
I've been using GetOldTweets3 recently and I don't think that you'll get user retweets from the result. For the replies, you can just get the reply for each record by adding tweet.to to your result and choose the record that has null for that.
Im currently getting all the tweets for a hashtag from a particular account.
By using this I can get hashtags' tweets :
tweepy.Cursor(api.search, q='#marketing', rpp=100).items(10)
By using this I can get tweets of a parituclar Id:
tweepy.Cursor(api.user_timeline, id="someid")
I need to combine these two to get all the tweets for a particular hashtag from an account.
I've tried multiple approaches to combine the above two api calls.
Just use the search API with the parameter q='#marketing from:user' to get tweets from #user containing #marketing.
You can directly use:
tweepy.Cursor(api.search, q="from:screen_name #hashtag")
Example:
tweepy.Cursor(api.search, q="from:someid #marketing")
This issue was raised in the tweepy github repo.
They should have added it in the documentation.
noofitem = 1000
tweets = tweepy.Cursor(api.search,q=['#iphone11, -filter:retweets'],since='2019-11-14',lang='en',tweet_mode='extended',retweeted=False).items(noofitem)
i = [tweet.full_text for tweet in tweets] #Tweet text
I am trying to get about 1000 tweets using tweepy. But the max tweets I get are around 600. Changing the date does not work. Any modification or other workarounds will be helpful. Thanks.
Please note that Twitter’s search service and, by extension, the
Search API is not meant to be an exhaustive source of Tweets. Not all
Tweets will be indexed or made available via the search interface.
Please refer to this link for more information: http://docs.tweepy.org/en/latest/api.html#help-methods
Probably you will need to set up a Stream to get the amount of data you need.
I'm working on an automatic text to speach generator using tweep and gTTS.
And what I'd like to is whenever a user tags my bot, my bot will reply with a generated TTS response of their tweet.
Example if Malcolm tweets "#bot Banana Bread" well the bot will reply to that tweet with a mp4 file of a voice saying "banana bread"
I think I could pull of the TTS generation with gTTS and some messing around.
However I don't know how I could automatically get the tweet Id and so the tweets text when I'm tagged.
The only method I see is to constantly refresh a
example = tweepy.Cursor(api.search, q='#bot').items(1)
and then
for tweet in example:
print tweet.text, tweet.id_str
and then store the id so that it only gets the latest posts and doesn't reply to the same tweet twice.
But this seems like a bit much, and I'm wondering if there's any faster/easier/more efficient way of doing this?
Your method is good : store tweet IDs you answered to, and check them before a new reply. With time, it can be a lot of IDs so you have to handle delete of very old ones.
Another way is to use the Twitter Account Activity API : via a webhook (an URL of your personnal web server), you can get mention events, then simply reply directly.
If i understand the official documentation, 1 free webhook is available with premium API.
Here is documentation :
https://developer.twitter.com/en/use-cases/engage#chatbots-and-automation
https://developer.twitter.com/en/docs/accounts-and-users/subscribe-account-activity/overview
I'm trying to collect tweets using certain hashtags using the twitter api and the tweepy module. I know how to get the 15 most recent tweets using a given hashtag using the code below:
import tweepy
auth = tweepy.OAuthHandler(consumer_key=con_key, consumer_secret=con_secret)
auth.set_access_token(acc_token, acc_secret)
#Connect to the Twitter API using the authentication
api = tweepy.API(auth)
tweet_list = api.search(q = '#23squadgoals')
However I was wondering what parameters I use to specify the number of the tweets to return. Also is there a parameter I can use to specify the timing? Like what I want to collect tweets that were tweeted a week ago?
ANy help would be appreciated!
Thanks,
Ben