Is it possible to list Direct Messages after a specified date? If I have a large number of Direct Messages, I'll reach the rate limit quickly if I have to page through many results. I'd like to track the last time I queried for DirectMessageEventsType.List and limit the next query to only messages sent/received after that date.
LinqToTwitter List DMs since a specified date
108 Views Asked by Andy Uzick At
1
There are 1 best solutions below
Related Questions in C#
- How to call a C language function from x86 assembly code?
- What does: "char *argv[]" mean?
- User input sanitization program, which takes a specific amount of arguments and passes the execution to a bash script
- How to crop a BMP image in half using C
- How can I get the difference in minutes between two dates and hours?
- Why will this code compile although it defines two variables with the same name?
- Compiling eBPF program in Docker fails due to missing '__u64' type
- Why can't I use the file pointer after the first read attempt fails?
- #include Header files in C with definition too
- OpenCV2 on CLion
- What is causing the store latency in this program?
- How to refer to the filepath of test data in test sourcecode?
- 9 Digit Addresses in Hexadecimal System in MacOS
- My server TCP doesn't receive messages from the client in C
- Printing the characters obtained from the array s using printf?
Related Questions in LINQ
- How to filter properties of derived classes in a DbContext with dynamic LINQ
- Query (or LINQ in Entity Framework) for getting user's rank
- How to return Inserted Updated Id in a Merge query
- Equivalent of LISTAGG in LINQ doesn't work
- Getting attribute from xml and printing it error
- Linq Grouping and workaround data entry errors in groups
- 'Unable to cast the type 'System.Guid' to type 'System.Object'. LINQ to Entities only supports casting EDM primitive or enumeration types.'
- linq issue accessing deep xml data
- OrderBy with lambda?
- Evaluating logical expressions recognized by ANTLR using the System.Linq.Expressions namespace
- Implementing List<T>, why wont it cast back to MyList after LINQ ? (Unable to cast object of type 'WhereListIterator`1)
- Linq GroupBy and Filter
- LINQ group by date and time
- How do I achieve client-side evaluation in LINQ?
- How do I create a Linq query that will return multiple complex properties in a sub property of a table?
Related Questions in TWITTER
- issue with Twitter API :
- Unable to use snscrape
- Unable to like a tweet with using Tweepy and Twitter/X v2 API
- automatic commenting for users on the home page of Twitter
- I have a tweet (X) download that is all code. I'm not a coder and I just want to read the message. Can someone help me do that?
- Web scraping using Selenium (not working)
- Twitter oauth2 link seems correct but not working
- Is logging via selenium blocked by twitter?
- Login with twitter using identity server is not working when using openidconnect
- Apache flume does not run hadoop 3.1.0 Flume 1.11
- How to verify Twitter oauth2.0 access token
- Twitter embedded timeline is showing "Nothing to see here"
- Twitter parsing with Selenium python
- Error in login with twitter function on React Native app
- Nothing is happening after solving FunCaptcha
Related Questions in LINQ-TO-TWITTER
- Twitter/X status post using LinqToTwitter is stuck
- LinqToTwitter List DMs since a specified date
- LinqToTwitter rate limits for sending DMs
- LinqToTwitter: How to return more than 20 followers?
- LinqToTwitter v5.1.2 AspNetAuthorizer doesn't contains a definition for CredentialStore
- linq-to-twitter Twitter flood get
- Truncated message tweets
- Visual Studio 2015 - Debug with HTTP connection problems
- LinqToTwitter I can't catch tweets
- Can't search for tweets with LinqToTwitter
- LinqToTwitter: timing issue with video media
- Twitter : When i used https://github.com/JoeMayo/LinqToTwitter for auth user , i m not getting any webhook
- How to query LinqToTwitter with multiple id's at once?
- How to use large numbers in angular 5+?
- async and await with Twitter direct_messages/events using LinqToTwitter
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
As you might already know, the only parameters in the Twitter API for listing DMs are
countandcursor. That said, here's a work-around that might be handy. It involves a LINQ to Objects query after the LINQ to Twitter query:The two variables that make this work are
isPastCreatedAtandlastCreatedAt. TheisPastCreatedAtflags the condition where a set of DMs (from a query of sizecount) contain one or more DMs that are older than a certain date. The date that qualifiesisPastCreatedAtislastCreatedAt. Essentially, we don't want to continue querying once we have tweets older thanlastCreatedAtbecause subsequent queries are guaranteed to return all the tweets older thanlastCreatedAt.The demo sets
lastCreatedAtto an hour earlier. Notice that it's using UTC time, because that's the time that Twitter uses. In your application, you should keep track of what this time is, re-setting it to theCreatedAtproperty of the oldest tweet received since the last set of queries.After each LINQ to Twitter query for DMs, there's a call to
CheckPastCreatedAt. This is whereisPastCreatedAtgets set. Inside of the method is a LINQ to Objects query. It queries the list of DMs that LINQ to Twitter just returned, checking to see if any DMs contain a date earlier than thelastCreatedAtdate. It uses theCreatedAtproperty and, as its name suggests, is the reason for the naming of the variables and method in this demo to ensure the query doesn't excessively waste rate limit. It also used theAnyoperator, which is much more efficient thanCount, but I digress.Notice that the
whilestatement inMainadds an additional condition to what you are probably using to iterate through the cursor:&& !isPastCreatedAt. That's what keeps you from going too far and wasting rate limit.There's only one more thing you need to do when this is done - filter out the DMs that you've already received to avoid duplicates. However, my gut feeling is that you already know that.
While this wasn't the answer you might have hoped for, it does outline an important pattern for anyone working with the Twitter API, whether LINQ to Twitter or any one of the other excellent libraries out there. That is, to make the query with what the Twitter API gives you and then filter the results locally. While some other libraries provide additional abstractions that sometimes feel like they help, LINQ to Twitter takes a more raw approach to stay closer to the Twitter API itself. For in situations like this, it's good to know intuitively about what is crossing the wire so you can reason about additional solutions that meet your needs.