gpt4 book ai didi

twitter - 获取用户配置文件和时间线时出现 Tweetsharp 问题

转载 作者:行者123 更新时间:2023-12-02 01:05:04 24 4
gpt4 key购买 nike

我们正在使用TweetSharp (TweetSharp 版本 = 2.3.1 和 Newtonsoft.Json 版本 = 5.0.6)用于在我们的 Web 应用程序中显示用户推文的 API。以下是我们在 asp.net mvc (C#) 应用程序中使用的代码:

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 });

我们在获取 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)

获取时间线推文时出现以下异常:

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)

并非所有 Twitter 用户都会遇到这种情况。这种情况只发生在少数拥有更多推文的用户身上。请建议如何处理?

最佳答案

我很确定这与 Twitter 用于新帐户的新用户 ID 长度有关。

每当使用新的 Twitter 帐户时,我都会遇到同样的错误。当查看旧帐户时,如果它们有来自新帐户的推文或提及,也会发生这种情况。

Tweetsharp 在一些引发异常的地方使用整数作为 user_id。

此部分有一个获取更新版本的链接,但该 github 现已删除。

关于twitter - 获取用户配置文件和时间线时出现 Tweetsharp 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19676216/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com