Twitter API 1.1 search/tweets - search by date - twitter

Since the "since" param is no longer in use, how can I search tweets older than specific date ? I understand how to use since_id, but in my case I don't have any historic tweet to take the tweet_id from. How is search by date done these days ?

It's an old question, but since it has no answer i share what i have found regarding this question by reading the docs and using the API.
Since and until params are only for maximum 9 past days.
Instead we can use since_id and max_id. You have to set them to unique ids of tweets. You can find one tweet in the specified time (from any user you want). Detect the id by using the API or simply by Developer tools of your browser.

You can use the until param:
Returns tweets generated before the given date. Date should be
formatted as YYYY-MM-DD. Keep in mind that the search index may not go
back as far as the date you specify here.

Related

Youtube v3 api PublishedAfter search

I'm trying to retrieve videos posted last 10 minuttes , but query is retrieving videos from 2015
https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=25&publishedAfter=2018-02-13T23%3A10%3A00Z&q=surfing&key={MyAPIKey}
After looking around in forums, only advice I found was try to add the PublishedBefore option, but that did not help either.
I used your example and get the 2015 results, but it looks like your datetime is in the future. How did you calculate the datetime?
I just now used format 'Y-m-d\TH:i:s\Z' for '10 min ago' and the time is quite different. This link returned the expected results.
https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=25&publishedAfter=2018-02-13T14%3A14%3A58Z&q=surfing&key={MyAPIKey}
So even though I responded 13+ hours after your post, my datetime is still about 9 hours before your example.
I managed to get this working. Here's the things you can double check. Make sure you are providing the correct date format as can be seen in the publishedAfter in the search.list:
2018-02-12T00:00:00Z
Also make sure the API Key you're using has the Youtube Data API "ENABLED" in your google dev console.
So, using your exact URI request, it looks like this:
https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=25&publishedAfter= 2018-02-12T00:00:00Z
&q=surfing&key=API_KEY
Our URL is below:
https://www.googleapis.com/youtube/v3/search?part=id%2Csnippet&maxResults=40&channelId=xxx&type=video&order=date&publishedAfter=2019-03-14T00:00:00Z&fields=items%2Fid%2Citems%2Fsnippet(title%2CpublishedAt)&access_token=yyy
Note I have replaced our Channel ID and Access Token with substitute values for this post.
The publishedAfter parameter is not working and has never worked for us. This wasn't a problem until the March 15-16 timeframe when something changed w/ the YouTube API and the order parameter is no longer being considered by their service. Since that time, all videos are being returned by their API in order of upload date (for us, this means starting w/ 2015).

Is there a way to search for old tweets on a specific date using a specific hashtag?

For example how could search for tweets using the #oldtweets sent on 5-29-16, from 8pm to 9pm.
According to the The Twitter Search API documentation, the query you want is not possible: https://dev.twitter.com/rest/public/search
The Twitter Search API searches against a sampling of recent Tweets
published in the past 7 days.
Beyond the last 7 days, what you want to achieve can only be done through manually searching an account on Twitter.
Another alternative would be to use https://webrecorder.io/
Scroll to the timeframe you want to record or you can attempt to capture the entire feed. Note the auto scrolling option as well.

Twitter4j - Getting tweets of a particular user in a time interval

I want to get the tweets of an user in a time interval, for example a user's tweets between a 6 months period. I can get all the tweets of a user with getUserTimeline functionality but it seems like it doesn't give me any option about any date interval.
I need something like since and until parameters which is provided by Query class of Twitter4j. I would use that class but it only support searching for keywords. Is there a way to accomplish this?
Thanks in advance.
I don't believe twitter itself provides any date/time related options for getting tweets (aka user timeline statuses).
If you can extract the tweet ID for the last tweet in that 6 month window, you can set that as max_id and then iterate backwards by setting the lowest tweet ID as max_id till you hit the start of the 6 month window.
The current version does not have any provision to get the tweets between a specific time interval using date and time with getUserTimeline functionality.
It can be done using since_id and max_id only AFAIK.
User TimeLine
Search tweets

How can I obtain a sampling of all tweets from a specific time period?

I want to gather samplings of all tweets from the past year. Being able to request tweets from a specific date would be great, but I'll take what I can get.
I do not want to find tweets by a specific user or containing a specific term, just a sampling of all tweets. The Twitter search API claims that a query term is optional, but if I try an empty query like
http://search.twitter.com/search.atom
as opposed to giving a search term,
http://search.twitter.com/search.atom?q=twitter
the response is
<hash>
<error>
You must enter a query.
</error>
</hash>
If the API really doesn't provide any functionality for this type of query, how can I hack around it? Are tweet ids roughly sequential by date and can I somehow use this info to grab bunches of tweets centered around an id of a tweet whose date I know?
You are referencing the obsolete documentation. If you read the current version you will find that a query is required.
You should also know that the Search API only provides results going back about two weeks. You might be able to find historical data from sites like infochimps.
Not useful for historical data, but in case someone stumbles across this question looking for a sampling of all current tweets, you want the streaming API. (This is my first foray into Twitter and I hadn't noticed it. I only saw the public timeline method in the normal API.)

Does the Twitter API allow filtering by username AND hashtag?

Can I get all the tweets of a particular user, in which a particular hashtag is used?
I could just get the past 100 tweets then filter them on my end, but it would be much more convenient if Twitter could do the filtering on their end.
Is this possible?
Twitter's Advanced Search lets you construct the query you desire. Unfortunately, search results only seem to be for tweets posted within the past 24 hours or so right now; might just be a temporary limitation, not sure.
In any case, your request URL might look something like this (note the JSON and Atom types):
http://search.twitter.com/search?q=%23HASHTAG+from:USERNAME
http://search.twitter.com/search.json?q=%23HASHTAG+from:USERNAME
http://search.twitter.com/search.atom?q=%23HASHTAG+from:USERNAME
But with the current timeframe limitation, it's not very practical.
I am reading the twitter documentation and they say right now it will include only 6-9 days of tweets. Link https://dev.twitter.com/docs/using-search
To do this search against v1.1 of Twitter's API (which requires OAuth), you'd issue a GET request to the a URL structured like:
https://api.twitter.com/1.1/search/tweets.json?q=from:whitehouse+#sotu
See their Search API's "How to build a query" section. You'll be constrained to tweets over the last 7 days, though.

Resources