Recent modification to Twitter API?
I wrote a very simple C# application to send Tweets between to Windows machines. To do this, each endpoint (ie this C#.NET desktop app that uses the TweetSharp library) has a timer, and when the Elapsed event fires all messages are gathered together with a GetDirectMessages() call, then these messages are parsed and processed by the endpoint.
My problem is that I built this over the course of a few hours two weeks ago and everything worked fine. I dusted it off and executed a week ago as well, no problems. Now, I break it out today and I am getting a very odd exception (see section EXCEPTION) that originate at the line "IEnumerable directMessage = service.ListDirectMessagesReceived();" (see section SOURCE). My question is, since my code hasn't changed, is it possible that the API has (I know I know terribly unlikely). Do any of the upstanding and erudite members of StackO have any thoughts?
Btw, I have checked and my ConsumerKey/Secret are valid, as is the cached OAuth access token that my authentication section uses. It's odd because I can pull my list of followers, check my rate limiting stats, etc. Also my NewtonSoft, Hammoch and TweetSharp references have not been updated/changed.
Thanks.
[SOU开发者_开发技巧RCE]
private struct message
{
public long id;
public string text;
public message(long i, string t)
{
id = i;
text = t;
}
}
private MessageEngine
{
/* Do auth -- excised for obvious reasons */
Timer timer = new Timer();
timer.Interval = 15000;
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
private List<message> GetDirectMessages()
{
try
{
//Declarations:
message message = new message();
List<message> messages = new List<message>();
/*line 344*/IEnumerable<TwitterDirectMessage> directMessages = service.ListDirectMessagesReceived();
//Fetch all current direct message:
foreach (TwitterDirectMessage directMessage in directMessages)
{
//Store each message into a list, in reverse older:
message = new message(directMessage.Id, directMessage.Text);
messages.Insert(0, message);
}
return messages;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return null;
}
}
private void timer_Tick(object sender, EventArgs e)
{
try
{
List<message> messages = GetDirectMessages();
LocalExecute(messages);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private bool LocalExecute(List<message> messages)
{
/* process messages */
}
[EXCEPTION]
Newtonsoft.Json.JsonSerializationException: Cannot deserialize JSON array into type 'TweetSharp.TwitterDirectMessage'.
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureArrayContract(Type objectType, JsonContract contract) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 412
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String reference) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 432
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 222
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueNonProperty(JsonReader reader, Type objectType, JsonContract contract) in d:\Development\Releases\Json\Working\Src\Newtonsoft.Json\Serialization\JsonSerializerInternalReader.cs:line 205
at TweetSharp.Serialization.SerializerBase.DeserializeJson(String content, Type type) in C:\Users\Dimebrain\Desktop\Src\tweetsharp\src\vs2010\TweetSharp.Next\Serialization\SerializerBase.cs:line 60
at TweetSharp.Serialization.JsonSerializer.AddDeserializedItem(String c, Type type, IList collection) in C:\Users\Dimebrain\Desktop\Src\tweetsharp\src\vs2010\TweetSharp.Next\Serialization\JsonSerializer.cs:line 131
at TweetSharp.Serialization.JsonSerializer.DeserializeCollection[T](String content) in C:\Users\Dimebrain\Desktop\Src\tweetsharp\src\vs2010\TweetSharp.Next\Serialization\JsonSerializer.cs:line 90
at TweetSharp.Serialization.JsonSerializer.Deserialize[T](String content) in C:\Users\Dimebrain\Desktop\Src\tweetsharp\src\vs2010\TweetSharp.Next\Serialization\JsonSerializer.cs:line 17
at Hammock.RestClient.DeserializeEntityBody[T](RestBase request, RestResponse`1 response) in C:\Users\Dimebrain\Desktop\Src\hammock\src\net35\Hammock\RestClient.cs:line 2285
at Hammock.RestClient.BuildResponseFromResult[T](RestBase request, WebQuery query) in C:\Users\Dimebrain\Desktop\Src\hammock\src\net35\Hammock\RestClient.cs:line 2212
at Hammock.RestClient.Request[T](RestRequest request) in C:\Users\Dimebrain\Desktop\Src\hammock\src\net35\Hammock\RestClient.cs:line 107
at TweetSharp.TwitterService.WithHammockImpl[T](RestRequest request) in C:\Users\Dimebrain\Desktop\Src\tweetsharp\src\vs2010\TweetSharp.Next\Service\TwitterService.cs:line 401
at TweetSharp.TwitterService.WithHammock[T](String path) in C:\Users\Dimebrain\Desktop\Src\tweetsharp\src\vs2010\TweetSharp.Next\Service\TwitterService.cs:line 378
at TweetSharp.TwitterService.WithHammock[T](String path, Object[] segments) in C:\Users\Dimebrain\Desktop\Src\tweetsharp\src\vs2010\TweetSharp.Next\Service\TwitterService.cs:line 383
at TweetSharp_Test.Form1.GetDirectMessages() in C:\Users\kmarks2\Documents\Visual Studio 2008\Projects\TweetSharp_Test\TweetSharp_Test\Form1.cs:line 344
As i can see from stack trace the TweetSharp.TwitterDirectMessage
class schema is different from what was expected by Deserializer, may be the Json data passed has changed from last time you checked.
Also I think the Tweetsharp had some issue related to this.
As i checked in changeset on codeplex there was a change to Fix direct messages with IDs using fluent.
Check it out here.
http://tweetsharp.codeplex.com/SourceControl/changeset/changes/8bf46a5230bc
Try downloading new TweetSharp v2.0.0.0 - Preview 9
精彩评论