Since Twitter Search Api 1.1 does not have since parameter to specify the start date, how do I get the tweets between 2 different dates(within 7 days limit)?
Note: I cannot use the since_id and max_id as parameters because I have only 2 dates and search query as inputs.
There is no direct way of doing it, but here are couple of ideas. You have a from date and a to date, right? So -
Set result_type to recent and until to your to date and count to 100.
from the result of 1, you get 100 tweets and you check if you've hit the from date, if not keep going till you reach from date using the max_id parameter.
Another idea would be -
Set result_type to recent and until to your from date. get the ID of the latest tweet from there. You need all the tweets since that ID till your to date ends.
So you set since_id to that ID you got in step 1 and keep requesting and updating since_id after each request till you hit your to date's end.
Related
I'm going to collect tweets about an event that has been happened 3 years ago, but I read somewhere that Twitter only let its API users to collect tweets not older than a week. So, I'd like to ask if this is true, how can I collect tweets from 3 or more years ago?
Get tweets using:
time_line_statuses = api.GetUserTimeline(screen_name=screen_name, include_rts=True)
Loop through time_line_statuses using a for loop
Check "created_at" property of each item to see if it is younger than your cut off date.
Each item has an "id" property. Value seems to grow with time. Lower ID = older.
Store 'id' of oldest status from time_line_statuses as oldest_id.
Call
.
time_line_statuses = api.GetUserTimeline(screen_name=screen_name, include_rts=True, max_id=)
Store oldest_id as previous_oldest_id
Repeat 1-6 while checking that oldest_id is not equal to previous_oldest_id before continuing the loop
You can only make 100 get request to twitter per hour. You need to count your Get() calls and have the program sleep for an hour when you've hit that limit. I don't know if their API has a limitation on how far back it can go. You may be able to save API calls if you can find the ID of the tweet that would be at the start of your cutoff date and seed this process from there.
Your only option is to pay for a service such as Gnip. Gnip provides an API that will let you search for tweets older than one week.
Due to the PowerShell methods of getting mailbox statistics from Office365 taking about 2 seconds per mailbox, I am working on getting the data from Office 365 Reporting web service, which takes only a few seconds for each 2000 mailboxes.
The problem I'm running into is that the stats are updated periodically and some historical data is kept, so there are numerous records for each user. I only want to get the latest record for each user, but I haven't been able to find a way to do that. The closest I've come is to use $filter=Date ge DateTime'2016-03-10T00:00:00' where the date is concatenated to a couple of days ago. Theoretically, if I sort by Date desc I should get the latest records first, and if there is a user that has a record for 3/10 and 3/11, the 3/11 record would get pulled first, which would work for me. But regardless of how I do the sort it seems to come back with the older records first.
Ideally, I would like to be able to set criteria so that it only returns the latest record for each mailbox, but I can't seem to figure out or find how to do that. The closest I've been able to come is to just start running queries filtered on specific dates, walking the date back a day on each query.
If I can get the latest records to be returned first, I would be able to work with that because I can just discard a record if I've already received a later one.
https://reports.office365.com/ecp/reportingwebservice/reporting.svc/MailboxUsageDetail/
?DelegatedOrg=nnn.onmicrosoft.com&$select=Date,WindowsLiveID,CurrentMailboxSize
&$filter=Date ge DateTime'2016-03-08T00:00:00'&$orderby=Date desc
So the questions are:
Is there a way to specify criteria so that only the latest record for each user is returned?
Is there a way to get it to order by Date descending--what am I doing wrong with the $orderby?
Thanks!
You can use $top=1 to get latest record by applying $orderby on date (desc). $filter and $skip may not require in this case.
https://reports.office365.com/ecp/reportingwebservice/reporting.svc/MailboxUsageDetail/?DelegatedOrg=nnn.onmicrosoft.com&$select=Date,WindowsLiveID,CurrentMailboxSize&$orderby=Date desc&$top=1
Your query looks fine, here is an another example from Odata sample service to get employee detail with most recent birth date.
http://services.odata.org/V4/Northwind/Northwind.svc/Employees?$select=EmployeeID,FirstName,LastName,BirthDate&$orderby=BirthDate%20desc&$top=1
I would like to search for a tweets within a range of between dates by using Twitter API v1.1
let Query query=new QUery(String query);
what is the query thats suits for my question ??
Thanks in advance for reply back.
I suggest setting until to limit your query to an upper date bound, e.g.:
query.setUntil("2014-07-01");
Then step back through the result set, by making subsequent search calls, until you hit your lower date bound.
Be aware that the search API may not contain all Tweets and it may not 'go back' as far as you need. For more information on it, and other query parameters, take a look at Twitter's documentation on searching.
You can use since_id & max_id to fetch tweets between a specific ID.
I want to know how to fetch tweets posted within the last three months, but I don't know how to find the tweet ID, which was posted before three months.
The twitter api has the search call method. You're already using since_id for the ids, but it looks like you want to use dates as well.
The two date methods (year-month-day) are:
hashtag since:1988-06-28 - Searches for "hashtag" and sent since date "1988-06-28".
hashtag until:2013-07-12 - Searches for "hashtag" and sent before date "2013-07-12".
Those two date examples (apart from the actual dates) are plucked straight from the documentation. If you want the last three months, just:
Calculate three months past to the following format: YYYY-MM-DD.
Use that in the since query
As of today, three months past is: 2013-04-12
since: 2013-04-12 - would be what you require in your GET request. Documentation Link.
I am using this URL http://search.twitter.com/search.json to grab tweets with the hash tag #SameHashTag. The feed only returns items within the past week. Twitter explains why here:
https://dev.twitter.com/docs/faq#8650
I really need to get the last 10 tweets, regardless of when they were created. What is the alternative?
Note I read about user_timeline, but that seems to be based on user instead of hashtag. I read about list_timeline, but that seems to pull tweets from a defined list of users instead of hashtag.
You can't get old tweets from Search API. If your hashtag doesn't change you could search it and save results every day and build your own history.