Tweetsharp issue while getting the UserProfile and TimeLine
Asked Answered
M

3

18

We are using TweetSharp(TweetSharp version = 2.3.1 and Newtonsoft.Json version = 5.0.6) API to show the Tweets of the Users in our web application. Below is the code that we are using in our asp.net mvc (C#) application:

var service = new TwitterService("ConsumerKey", "ConsumerKeySecret");
service.AuthenticateWith("TwitterToken", "TwitterTokenSecret");
TweetSharp.TwitterUser tuSelf = service.GetUserProfile(new GetUserProfileOptions() { IncludeEntities = false, SkipStatus = false });
if (tuSelf != null)
{
//Get the User Details
}
var tweets = service.ListTweetsOnUserTimeline(new ListTweetsOnUserTimelineOptions { Count = 5 });

We are getting the Following exception while getting the UserProfile:

System.OverflowException: Value was either too large or too small for an Int32.

Generated: Wed, 30 Oct 2013 05:48:41 GMT

System.OverflowException: Value was either too large or too small for an Int32.
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at Newtonsoft.Json.JsonTextReader.ParseNumber()
   at Newtonsoft.Json.JsonTextReader.ParseValue()
   at Newtonsoft.Json.JsonTextReader.ReadInternal()
   at Newtonsoft.Json.JsonReader.ReadAsInt32Internal()
   at Newtonsoft.Json.JsonTextReader.ReadAsInt32()
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at TweetSharp.SerializerBase.DeserializeJson(String content, Type type)
   at TweetSharp.JsonSerializer.DeserializeJson(String content, Type type)
   at TweetSharp.JsonSerializer.DeserializeSingle(String content, Type type)
   at TweetSharp.JsonSerializer.DeserializeContent(String content, Type type)
   at TweetSharp.JsonSerializer.Deserialize[T](RestResponseBase response)
   at Hammock.RestClient.DeserializeEntityBody[T](RestRequest request, RestResponse`1 response)
   at Hammock.RestClient.BuildResponseFromResult[T](RestRequest request, WebQuery query)
   at Hammock.RestClient.Request[T](RestRequest request)
   at TweetSharp.TwitterService.WithHammockImpl[T](RestRequest request)
   at TweetSharp.TwitterService.WithHammock[T](String path)
   at TweetSharp.TwitterService.WithHammock[T](String path, Object[] segments)
   at TweetSharp.TwitterService.GetUserProfile(GetUserProfileOptions options)
   at TweetApp.Web.Controllers.TwitterController.GetFollowersAndTweets(TwitterSettings twitterSettings)
   at TweetApp.Web.Controllers.TwitterController.ViewTwitter(Nullable`1 Id)
   at lambda_method(Closure , ControllerBase , Object[] )
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<>c__DisplayClass2a.<BeginInvokeAction>b__20()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
   at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
   at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
   at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

And the below exception while getting the Timeline Tweets:

Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'TweetSharp.TwitterStatus' 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<T> 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. Path '', line 1, position 1.

Generated: Wed, 30 Oct 2013 04:45:03 GMT

Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'TweetSharp.TwitterStatus' 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<T> 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.
Path '', line 1, position 1.
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureArrayContract(JsonReader reader, Type objectType, JsonContract contract)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at TweetSharp.SerializerBase.DeserializeJson(String content, Type type)
   at TweetSharp.JsonSerializer.DeserializeJson(String content, Type type)
   at TweetSharp.JsonSerializer.AddDeserializedItem(String c, Type type, IList collection)
   at TweetSharp.JsonSerializer.DeserializeCollection(String content, Type type)
   at TweetSharp.JsonSerializer.DeserializeContent(String content, Type type)
   at TweetSharp.JsonSerializer.Deserialize[T](RestResponseBase response)
   at Hammock.RestClient.DeserializeEntityBody[T](RestRequest request, RestResponse`1 response)
   at Hammock.RestClient.BuildResponseFromResult[T](RestRequest request, WebQuery query)
   at Hammock.RestClient.Request[T](RestRequest request)
   at TweetSharp.TwitterService.WithHammockImpl[T](RestRequest request)
   at TweetSharp.TwitterService.WithHammock[T](String path)
   at TweetSharp.TwitterService.WithHammock[T](String path, Object[] segments)
   at TweetSharp.TwitterService.ListTweetsOnUserTimeline(ListTweetsOnUserTimelineOptions options)

Its not happening for all the Twitter Users. It happens only for few Users who has more tweets. Please suggest how to handle this?

Marceau answered 30/10, 2013 at 7:26 Comment(0)
D
17

I'm pretty sure this is to do with the new user id length Twitter is using for new accounts.

I had the same error whenever working with a new twitter account. It also occurs when looking at older accounts if they have tweets or mentions from new accounts.

Tweetsharp is using integers for the user_id in a few places which is throwing the exceptions.

This section had a link to fetch an updated version, but that github has now been removed.

Rob

Dioptase answered 31/10, 2013 at 0:2 Comment(8)
clone TweetSharp. open the TweetSharp.Core project. Install-Package Hammock if you don't have it. Install-Package Newtonsoft.Json if you don't have it. Build just the TweetSharp proj. Copy the bin\Debug\TweetSharp.dll to whatever project you are using TweetSharp (remove ref, delete old, copy in new, add ref to be safe). I had the same issue with a new test Twitter account, this fixed it, but not with my old personal account. Cheers for the heads up @RobBozarth
If you are facing any problem building the latest codebase, please find the dlls here .. github.com/mdrahman/TweetSharp.DLLLeprous
Nuget has been updated with an unoffical version. The Official version is broken, but the unoffical one has this fix in it.Epitaph
@GazWinter Keep me up to date if you would on an Offical Fix on Nuget if you see one, and I'll do likewise. Thanks for the info.Thermionics
Thank you @GazWinter nuget.org/packages/TweetSharp-Unofficial and source: github.com/timothy-makarov/tweetsharp One downside is that the unofficial requires exactly json.net 6.0.0 and I have a newer versionPainting
fyi about the unofficial nuget: You are trying to install this package into a project that targets 'WindowsPhone,Version=v8.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package authorPainting
doesn't work, I am using v 2.3.1 only but still i am getting this error.Unruly
link to the GitHub is brokenHeiney
C
14

Twitter has changed their id from Int32 to Int64 and TweetSharp has not updated to handle this.

To fix:

  1. In the packages.config file delete the reference to TweetSharp.
  2. Open the Package Manager Console
  3. PM> Install-Package TweetSharp-Unofficial

And boom. That should do it.

Corking answered 1/9, 2014 at 2:7 Comment(2)
What is the difference between both ? As it says unofficial. is it safe to use it ?Unruly
@RohitArora the unofficial version is a fork of the original which has updated the 'id' field. I can't guarantee it is safe, but I am using it.Corking
W
3

I have this issue , I just Update JSON.Net package and its fixed.

Go to Solution Exp -> References right click -> Manage Nuget pack -> Check Updates and update Json.net pack.

Walkyrie answered 16/9, 2014 at 16:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.