最近对 Twitter API 进行了修改?

发布于 2024-10-12 23:43:04 字数 5552 浏览 1 评论 0原文

我编写了一个非常简单的 C# 应用程序,用于在 Windows 计算机之间发送推文。为此,每个端点(即使用 TweetSharp 库的 C#.NET 桌面应用程序)都有一个计时器,当 Elapsed 事件触发时,所有消息都会通过 GetDirectMessages() 调用收集在一起,然后由以下方法解析和处理这些消息:终点。

我的问题是,我在两周前的几个小时内构建了这个,一切都运行良好。我一周前也把它掸掉并执行,没有问题。现在,我今天将其分解,并得到一个非常奇怪的异常(请参阅异常部分),该异常源自“IEnumerable directMessage = service.ListDirectMessagesReceived();”行(参见来源部分)。我的问题是,既然我的代码没有改变,API 是否有可能改变(我知道我知道极不可能)。 StackO中正直博学的成员们有什么想法吗?

顺便说一句,我已经检查过,我的 ConsumerKey/Secret 是有效的,我的身份验证部分使用的缓存的 OAuth 访问令牌也是有效的。这很奇怪,因为我可以拉出我的关注者列表,检查我的速率限制统计数据等。而且我的 NewtonSoft、Hammoch 和 TweetSharp 参考文献还没有更新/更改。

谢谢。

[来源]

    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 */
    }

[例外]

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

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.

[SOURCE]

    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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最偏执的依靠 2024-10-19 23:43:04

正如我从堆栈跟踪中看到的 TweetSharp.TwitterDirectMessage 类架构与反序列化器预期的不同,可能是传递的 Json 数据与上次检查时相比发生了变化。

我还认为 Tweetsharp 有一些与此相关的问题。

当我在 codeplex 上检查变更集时,使用 Fluent 修复带有 ID 的直接消息发生了更改。

在这里查看一下。

http://tweetsharp.codeplex.com/SourceControl/changeset/changes/8bf46a5230bc

尝试下载新的 TweetSharp v2.0.0.0 - Preview 9

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文