-
Notifications
You must be signed in to change notification settings - Fork 218
Tweetinvi Events
linvi edited this page Jun 8, 2015
·
2 revisions
Tweetinvi events are global events that can be used to gain more control and debug over what Tweetinvi does for you.
This event is very useful. It allows developers to check which requests are going to be performed through Tweetinvi. More importantly it allows developers to modify or cancel a WebRequest.
Here is a non-exhaustive list of what you can use this event for.
- Log queries performed with Tweetinvi
- Check RateLimits before performing a query
- Modify credentials based on application state
- Cancel queries
TweetinviEvents.QueryBeforeExecute += (sender, args) =>
{
var rateLimits = RateLimit.GetQueryRateLimit(args.QueryURL);
if (rateLimits != null)
{
// 2 - Your code to await for rate limits
}
// 3 - Your strategy to use multiple credentials
var shouldChangeCredentials = true;
if (shouldChangeCredentials)
{
var queryDetails = args.TwitterQuery;
queryDetails.OAuthCredentials = alternateCredentials;
}
// 4 - Cancel your query
args.Cancel = true;
};
This event allows developers to check if a specific query has been successful and what it returned. The event args contains the same information with few additional properties as demonstrated below.
TweetinviEvents.QueryAfterExecute += (sender, args) =>
{
var json = args.JsonResult;
var success = args.Success;
var completedDateTime = args.CompletedDateTime;
};