Skip to content

Tweetinvi Events

linvi edited this page Jun 8, 2015 · 2 revisions

Overview

Tweetinvi events are global events that can be used to gain more control and debug over what Tweetinvi does for you.

Before Query Executes

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.

  1. Log queries performed with Tweetinvi
  2. Check RateLimits before performing a query
  3. Modify credentials based on application state
  4. 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;
};

After Query Executes

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;
};
Clone this wiki locally