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
Related
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.
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.
First of all let me note that this is the first time I am using the Twitter API, so I could be missing something obvious.
What I want to do is get all tweets that include a given hashtag. My research lead me to use the twitter search API. I've tried using it, however I only seem to get about 6 tweets, when I know that the hashtag has thousands of tweets.
So my question is, how do I actually get all of the tweets for a given hashtag? Or at least more than 6 tweets.
For reference, there is the python code I am using to fetch tweets with the #hillarysoqualified hashtag (replace the keys obviously):
from twitter import Twitter, OAuth
ACCESS_TOKEN = 'access_token'
ACCESS_SECRET = 'access_secret'
CONSUMER_KEY = 'consumer_key'
CONSUMER_SECRET = 'consumer_secret'
oauth = OAuth(ACCESS_TOKEN, ACCESS_SECRET, CONSUMER_KEY, CONSUMER_SECRET)
t = Twitter(auth=oauth)
query = t.search.tweets(q='%23hillarysoqualified')
for s in query['statuses']:
print(s['created_at'], s['text'], '\n')
It appears I had not read the docs - Twitter search API only gives you tweets from the last week. Hope this helps if someone else tries to do what I did without knowing.
yes, the standard search API gives you only access to last 7 days, but you request an access to a premium Search API sandbox for free which gives access to up to 30 days. you can find more information here https://developer.twitter.com/en/docs/tweets/search/overview
I need to scrape the exact number of tweets that are generated under certain Twitter accounts on a daily basis. As well as the number of followers.
As far as I know Twitter's streaming API is not complete.
Does anyone know a suitable source - not necessarily from Twitter. I am already scraping from Topsy but I could not figure out yet how to limit the displayed tweets to only a single account. I do not even need the content but only the number of generated tweets and the number of followers.
Thank you!!!
There are several python modules that can be used.
Here is how you could go about getting a list of followers with Twython
(from: How to get twitter followers using Twython?)
from twython import Twython
twitter = Twython()
followers = twitter.get_followers_ids(screen_name = "ryanmcgrath")
for follower_id in followers:
print "User with ID %d is following ryanmcgrath" % follower_id