How to query twitter API with respect to time using Tweepy? - twitter

I have access to Twitter's API, and I'm using the Tweepy module to query tweets. However, I can't figure out how to search tweets in a specific time slot, like march 1st - july 20th.

The Twitter API only allows you to query back in time for 7 days, see the API documentation. That is, unless you pay for that extra access.

Related

How do I retrieve a user's tweets of last 7 days using twitter API?

I want to pull tweets from an authenticated user's home timeline (user + people the user follows) of past 7 days. How can I do this? The documentation of GET statuses/home_timeline only provides a count parameter and some other parameters like since_id and max_id which I don't really understand.
Documentation: https://developer.twitter.com/en/docs/twitter-api/v1/tweets/timelines/api-reference/get-statuses-home_timeline
Is there any other endpoint which might help? Or is it just impossible to do so?
The recent search in the Twitter v2 API can do what you are asking.
Here is an example:
https://api.twitter.com/2/tweets/search/recent?query=from:username is:verified&max_results=100
The Research Search API can only search in the last 7 days by default. You can return a maximum of 100 tweets per request.
Docs:
https://developer.twitter.com/en/docs/twitter-api/tweets/search/integrate/build-a-rule

How to get all posts in a limited date range in Instagram Graph API?

I need to retrieve all posts from the instagram page associated to my business account.
The Instagram API documentation does not mention any way to get media only between a certain period.
I´ve tried a analog request with the one I use in Facebook API
/{my_business_account_id}/media/?limit=100&period=day&access_token={my_user_access_token}&since=2019-02-23&until=2019-02-24&fields=id,caption,like_count,media_type,media_url,timestamp,permalink,username
That request works but ignores the since / until parameters and retrieve literally all my posts.
How do I limit the date range of the retrieved posts?
Answer is here: https://stackoverflow.com/a/50946962/5696380:
Unfortunately the since and until parameters are not supported on
this endpoint and this endpoint has only support cursor based
pagination.

Twitter API get Account tweet likes per day

I need to get the following stats for a twitter account on daily basis:
Likes per day
Replies per day
Retweets per day
Followers per day
Just like facebook graph API request "/me/insights/page_impressions?period=day"
I am trying twitter ads api but its not working. Can someone please tell me exact api and query.
Thanks in advance!!
This is possible using the commercial Twitter Engagements API from Gnip. The Ads API is for promoted content.

Is it possible to access the live tweets of a user using tweepy?

I am trying to access live tweets of a user whenever he tweets it. So, all I want is something that continuously monitors a user account and whenever he tweets something I have to capture it. All the tweets are random so I cannot use any filters.
For any security reasons, if I cannot access other's tweets can I do it on my own account?
With tweepy you can connect to the REST API or the Streaming API.
Using the Streaming API you can use the filter endpoint to select the users you wish to follow with that streaming connection and you will receive updates as they get published.
Twitter's documentation: https://dev.twitter.com/docs/api/1.1/post/statuses/filter, tweepy's code: https://github.com/tweepy/tweepy/blob/master/tweepy/streaming.py
Tweepy's documentation doesn't give examples on the Streaming functions but you can find sample code searching at GitHub or StackOverflow for "tweepy filter follow".
Tweepy talks to the Twitter REST API, and the REST API doesn't have any way to react to someone posting a tweet.
HOWEVER...
You could certainly write an application that retrieves the tweets of a partcular user and looks for any tweets that weren't there the last time you checked.
You'd want to be cautious about how often you check so you don't run afoul of the API rate limits.

Replacement for Twitter RSS API?

I'm currently using Twitter's RSS API (example) to retrieve people's tweets for an app. However, once version 1.1 of their API comes out, I won't be able to do this anymore. What's a simple replacement I can use for this?
Unfortunately the answer is: "There is none."
Twitter continues to lock down their platform, as they have since the switch to OAuth. If you want to add content to Twitter, you can do that easily. If you want to get content out of Twitter, well, you'll have to conform to Twitter's requirements.
RSS was an easy way of getting content out of Twitter, and so they killed it. They'll tell you that it wasn't really used, but that's a load of bull and they know it, but it sounds good and most people will simply swallow it.
There is a workaround that you can use until March 2013:
https://api.twitter.com/1/statuses/user_timeline/UserName.rss
Replace 'UserName' with the actual twitter username you want.
But after sometime in March/April 2013, that will cease to work and you'll have to use OAuth and json to parse Twitter feeds.
Use Twitter RSS - Google Apps Script from github to convert Twitter API 1.1 to RSS. Using this option you can get search results, users' timelines, users’ favorites or even Twitter Lists.
I've put together two mit licensed php scripts and instructions so you can fetch and cache twitter user timelines as RSS..
The most important is to cache the tweets since you are only allowed to call the API 15 times per 15 minutes..
Have a look at twitterrss.net
I've been looking for an answer to this for a while, basically as I wanted to provide a replacement for the Twitter triggers in IFTTT. When IFTTT removed them we could use Twitter's RSS feeds. However now, with v1 of their API retired, you have to authenticate any requests and they no longer off RSS feeds. It's a shame because it's closing the door for a lot of newbie developers out there.
I'd definitely recommend checking out twitter-rss.com in the answer above, but you might want to check out a solution I've come up with. It is called Twools and it's almost ready.
Twools started off as a way to get back RSS feeds from Twitter. Twitter
retired version 1 of their API in June 2013 as well as retiring RSS feeds. As
well as not having access to RSS feeds, you need to be authenticated to use
the API which
raises the bar for Twitter users and developers. It has been my intention to
make this as easy as possible for you install, however you do need to install
this on your own website (PHP is required). It is just a case of editing a few
lines in a file (with your Twitter app details) and uploading to your website.
Twools offers a number of RSS feeds from the Twitter API:
Your home timeline
User timeline (yours or another user's)
Your mentions
Your favorites
List timeline (from a list that you own)
Direct messages received (disabled by default)
Direct messages Sent (disabled by default)
Twitter Search
New followers
New friends
You can filter the results from the Twitter API by only outputting tweets
containing certain keywords, hashtags or screen names or even by the app used
to send the Tweet. As well as that you can filter based on the user (currently
their location and language). Finally, you can modify the data outputted in
the RSS feed by removing URLs, screen names, hashtags etc or share your recipe
with other folders. As well as an RSS feed generator, Twools has a basic
direct message spam filter (experimental- use at your own risk!) and a simple
social media management tool (basically an HTML version of the RSS filters).
You can also keep an eye on your API usage on the Status page.
With Twools and your app you could
Your tweets when you mention a specific hashtag
Your Twitter Faves:
Get new followers from the a certain country or location
Get tweets when someone mentions Starbucks negatively in a Tweet in the UK
Get tweets when someone tweets to an article on your website
For more information, see http://twools.it/

Resources