Skip to content

Tweetinvi 1.2

Compare
Choose a tag to compare
@linvi linvi released this 14 Dec 16:31

Breaking Changes

  • IMPORTANT : Please read if you use Tweetinvi in multiple threads with multiple credentials. Thread credentials has slightly changed to fix a bug that resulted in the incorrect credentials to be picked in some cases. Read more in the Thread Credentials section
  • Only the Extended Tweets are now available in the ITweet.Entities property. as opposed to before when the property was returning both Extended Entities AND Legacy Entities

Nuget

With the addition of .NETCore to nuget targets for the library, some people started to experience problems regarding the dependencies that were added based on their platforms specifically for Xamarin and Mono. We are pleased to announce that this has been fixed and in addition projects with classical .NET Framework will be able to use Autofac >= 3.5.2 again.

Streams

TweetEventArgs now return an ITweet and its associated json to simplify the life of developers!

Custom Accept Headers

To improve the flexibility of Tweetinvi, ITwitterQuery now provide a new property AcceptHeaders that you can update to customize the Accept headers that will be used to execute the HttpRequest.

Messages

You can now access private message entities via the IMessage.Entities property.

Upload

A new method allow you to rely on Tweetinvi to synchronously wait for a media to be uploaded and processed by the Twitter Upload API.

var binary = File.ReadAllBytes(@"C:\Users\linvi\Pictures\sample_video.mp4");
var media = Upload.UploadVideo(binary, mediaCategory: "amplify_video");
// The media cannot be used for the moment.

var mediaWithMetadata = Upload.WaitForMediaProcessingToGetAllMetadata(media);

// Now we can access the media's metadata.
var videoType = mediaWithMetadata.UploadedMediaInfo.VideoDetails.VideoType;

Thread Credentials

This topic is about threads and is slightly more technical than usual, please read attentively.

You can be affected by this change...

  • If you run an application with multiple credentials.
  • If you use these different credentials on multiple threads.
  • If you use object instances methods (ITweet, IUser, IMessage...)
  • If object instances created in a thread T1 are being used to invoke methods from another thread T2 (T1 and T2 having a different set of credentials)

Technical Explanation

Most developers uses Auth.SetUserCredentials in order to set the credentials used within the current running thread. Any object (tweet, user, message...) created in the context of this thread are being constructed with injected controllers/factories/helpers.

Before version 1.2 a newly created object was storing a controller that helped him execute any operation related with this object type (e.g. ITweet objects are capable of invoking a PublishRetweet() method).

The problem was that the controller within the newly object had an indirect reference to the credentials of the thread used for the creation of the object.

Therefore invoking tweet.PublishRetweet in a thread T2 different from the constructor thread T1, incorrectly resulted in the credentials of T1 to be used to run PublishRetweet whilst developers would have expected the credentials of T2 to be used to run the instance method.

In version 1.2 PublishRetweet correctly uses the running thread T2 credentials.

Some code to explain

ITweet tweet = null;
var T1 = new Thread(() =>
{
    // We initialize the T1 credentials
    Auth.SetUserCredentials(creds1);

    // We have a tweet that was created with T1
    tweet = Tweet.PublishTweet("hello");
});

T1.Start();

// The tweet variable is now an instance of ITweet
T1.Join();

// We initialize the credentials of the main thread T2
Auth.SetUserCredentials(creds2);

// Here is where the bug happened before 1.2
// PublishRetweet was running with creds1 (T1) instead of creds2
// In version 1.2, this operation will be executed with creds2
tweet.PublishRetweet(); 

Other

  • Added a new field PublishTweetParameters.ExcludeReplyUserIds
  • Autofac >= 3.5.2 dependency is back
  • Added support of 308 status code for TON Api
  • UploadProcessingInfo is now an enum that help developers to know the current stage of an upload.
  • Extended Tweets have added new HTTP error codes. They are now supported by the library.

Bug Fixes

  • Extended Tweet suffix length has been updated to properly reflect the value from Twitter
  • QuotedTweet throwing an error for being > 140 characters with Extended Tweets