Quantcast
Channel: Tweetinvi a friendly Twitter C# library
Viewing all articles
Browse latest Browse all 4126

Released: Tweetinvi 0.9.6.x (Mar 28, 2015)

$
0
0

Tweetinvi Update 0.9.6.0

Quick Overview

Custom Parameters

When an action can be performed with a 'RequestParameters' class (e.g. Search, Timeline, Message...), you will now be able to specify CustomQueryParameters.

The goal of such a feature is to give the ability to developers to quickly add new parameters to existing Endpoints. This is required so that they do not have to wait for the next release of Tweetinvi to use such parameters.

var searchParameters = Search.CreateTweetSearchParameter("hello");
searchParameters.AddCustomQueryParameter("include_entities", "false");

Upload

Upload now uses the new Twitter endpoint. This update will result in developers to be able to publish up to 4 images in a single tweet.

byte[] file1 = File.ReadAllBytes("filepath1");
byte[] file2 = File.ReadAllBytes("filepath2");

var helloTweet = Tweet.CreateTweet("hello");

helloTweet.AddMedia(file1);
helloTweet.AddMedia(file2);

// It will now publish 2 images
helloTweet.Publish();

If you only want to upload media, you can now do it and get back the upload id from it.

byte[] file1 = File.ReadAllBytes("filepath1");
var uploadInfo = Upload.UploadBinary(file1);
var uploadId = uploadInfo.UploadedMediaInfo.MediaId;

RateLimit Tracker

You will now be able to track the RateLimits but handle them yourself. A third option called TrackOnly will no longer await for the RateLimits to be available but will still continue to keep track of the RateLimits within the application.

// The previous code 
RateLimit.UseRateLimitAwaiter = true;

// Has now been changed into
RateLimit.RateLimitTrackerOption = RateLimitTrackerOptions.TrackAndAwait;

// The new feature is now available with the TrackOnly option
RateLimit.RateLimitTrackerOption = RateLimitTrackerOptions.TrackOnly;

RateLimit - TwitterQuery the new Revolution!

This advance feature will allow some developers to gain more granular control over the RateLimit of Twitter.

In 0.9.6.0, I have decided to give more power to developers and allow them to alter a query as they like. For example you will be able change a query URL that is going to be invoked. This will allow some developers to add custom parameters to the Tweetinvi generated queries.

But the most interesting point is that it opens a complete new way to control the RateLimits. You will now be able toCancel a query or Change the Credentials that a query will use.

var emergencyCredentials =TwitterCredentials.CreateCredentials("at", "ats", "ck", "cs");
TweetinviEvents.QueryBeforeExecute += (sender, args) =>
{
    var rateLimit = RateLimit.GetQueryRateLimit(args.QueryURL);
    if (rateLimit != null&& rateLimit.Remaining == 0)
    {
        if (emergencyCredentials != null)
        {
            args.TwitterQuery.OAuthCredentials = emergencyCredentials;
        }
        else
        {
            args.Cancel = true;
        }
    }
};

NOTE : Please note that the Twitter Query concept will be improved in Tweetinvi 0.9.7.0.

Search Filters

This new release introduces the Search Filters (Images, Videos, Hashtags, Links, News, Replies, Verified).

A previous property called TweetSearchFilters has been renamed to TweetSearchType. This property allows to specify which type of Tweet we want to receive from the Search.

The Filters property just filter the content based on its type or its content.

// This code will return the tweets in relation with manga but all this tweet will contain a video.var searchParameter = Search.CreateTweetSearchParameter("manga");

// Add some filters to the query
searchParameter.Filters = TweetSearchFilters.Videos;

// Specify which mode of search we want to use
searchParameter.SearchType = SearchResultType.Popular;

// Specify which type of tweets needs to be retrieved
searchParameter.TweetSearchType = TweetSearchType.OriginalTweetsOnly;

Entities Update & Video

Tweet Entities have been modified "significantly". The previous propertyExtendedEntities has been removed.

Instead, the Entities property will now return the ExtendedEntities. If the ExtendedEntities are not available in the json, theEntities property will return the LegacyEntities.

In addition Tweetinvi now supports the Video entities.

var tweet = Tweet.GetTweet(tweetWithVideoId);
var media = tweet.Entities.Medias[0];
if (media.MediaType == "video")
{
    var duration = media.VideoDetails.DurationInMilliseconds;
}

Streams

Added parameters

var s = Stream.CreateSampleStream();

// This parameter allow you to filter the tweets by using Twitter filter model
s.FilterLevel = StreamFilterLevel.Low;

// I do not advise disabling the Stall warnings but it is no longer forced// This will result in the StallWarnings event to not be raised anymore
s.StallWarnings = false;

Multiple languages support

Tweetinvi now supports multiple languages with a new set of methods.

var stream = Stream.CreateSampleStream();

// Add multiple languages
stream.AddTweetLanguageFilter(Language.French);
stream.AddTweetLanguageFilter(Language.English);
stream.AddTweetLanguageFilter(Language.Spanish);

// Remove a language from the list
stream.RemoveTweetLanguageFilter(Language.Spanish);

// Access the languages set for the streamvar filteredLanguages = stream.FilteredLanguages;

// Remove all languages filters to get everything
stream.ClearTweetLanguageFilters();

Exception

Stream Exception handling have been improved. The ExceptionHandler no longer logs exceptions from Streams.

Report User For Spam

It is now possible to report a user for spam.

User.ReportUserForSpam(23829382);

Tweetinvi Events

The events have been reordered so that the AfterQueryExecute is now invoked after the RateLimit has been updated.

QueryBeforeExecuteEventArgs now has a Cancel property that allow you to prevent a query for being executed.

TweetinviEvents.QueryBeforeExecute += (sender, args) =>
{
    if (args.QueryURL == "This is a crazy query!")
    {
        // I want to cancel this query cause its crazy to execute it!
        args.Cancel = true;
    }
};

Twitter Configuration

Users now have access to the Twitter Configuration endpoint as requested.

var configuration = Help.GetTwitterConfiguration();

Development on Mono and Xamarin Android/iOS

Tweetinvi library has been improved and is compatible with Mono 3.0 and Xamarin. You can therefore create your Android Twitter application with Tweetinvi!

I will try to add Tweetinvi to the Xamarin Packages.

Minor Updates

Exception Handler

Added a method to add a TwitterException from the static Exception Handler
The ExceptionHandler no longer logs exceptions from Streams.

Tweet Lookup

Tweet lookup is now able to manage more than 100 items without throwing an exception.

var tweets = Tweet.GetTweets(tweetIds);

Bugs Resolved

  • The credentials creator now correctly handle and swallow WebExceptions thanks to the ExceptionHandler.
  • The WebCredentials Creator now correctly parse url with parameters that have been encoded.
  • Cursor Query is now correctly handling request that return a previous cursor of -1 and a next cursor of 0.

Viewing all articles
Browse latest Browse all 4126

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>