Deserialization issue when retrieving Animated gifs/MP4

api
csharp
tweetsharp

#1

Hello,

We are currently using the Twitter API TweetSharp v 2.3.1 in our application, and we are facing an issue when retrieving posts (tweets and direct messages) that contain animated Gifs/MP4.

For example when we try to get the list of the DMs using this code below:

TwitterService twitterService = new TwitterService(consumerKey, consumerSecret, accessToken, accessTokenSecret);
ListDirectMessagesReceivedOptions directMessageOptions = new ListDirectMessagesReceivedOptions { SinceId = twitterAccount.SinceId, MaxId = maxId };
var directMessages = twitterService.ListDirectMessagesReceived(directMessageOptions);

The following exception is raised:

Cannot deserialize the current JSON array (e.g. [1,2,3]) into type ‘TweetSharp.TwitterDirectMessage’ because the type requires a JSON object (e.g. {“name”:“value”}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {“name”:“value”}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.

Here is a more detailed exception message :

Exception:Thrown: “Error converting value “animated_gif” to type ‘TweetSharp.TwitterMediaType’. Path ‘entities.media[0].type’, line 132, position 30.” (Newtonsoft.Json.JsonSerializationException)
A Newtonsoft.Json.JsonSerializationException was thrown: “Error converting value “animated_gif” to type ‘TweetSharp.TwitterMediaType’. Path ‘entities.media[0].type’, line 132, position 30.”

Indeed, the media type is unknown. When we open the Tweetsharp reference in the Object Browser, we only find “photo” media type.

Are we missing anything?

Thank you for your help


#2

It looks like 2.3.1 was published in June 2013, so there’s a good chance that it won’t support Animated GIFs or videos, since both formats were added to Twitter in 2015. Is there any chance to look at an alternative library, or see if there are any outstanding patches to the TweetSharp project to add that functionality?


#3

Thank you for your reply.

We tried a few other solutions but it didn’t work. Can you please recommend us an alternative that would work for Gifs/MP4 format?


#4

Tweetinvi is an active project, updated regularly to support Twitter latest changes. It does support gif and mp4.

It is also a Portable Class Library, meaning that you can use it across a wide range of devices.


#5

Hi,

This solution sounds interesting, I will certainly try it.
Thank you!