【问题标题】:Getting twitter Profile data in C#在 C# 中获取 twitter 个人资料数据
【发布时间】:2012-06-18 05:20:51
【问题描述】:

我正在用 C# 创建一个应用程序,用户在其中输入他们的姓名,并从 Twitter 接收相应的个人资料数据。我暂时没有使用 API。如果我使用:

https://api.twitter.com/1/users/show.json?screen_name=kool_aid_wino

响应是这样的 JSON 消息。

{"id":184937673,"id_str":"184937673","name":"Brautigan's Ghost","screen_name":"Kool_Aid_Wino","location":"","description":"Author Richard Brautigan floating through time. Fan Account.","url":null,"protected":false,"followers_count":1803,"friends_count":623,"listed_count":97,"created_at":"Mon Aug 30 21:21:12 +0000 2010","favourites_count":0,"utc_offset":-18000,"time_zone":"Quito","geo_enabled":false,"verified":false,"statuses_count":653,"lang":"en","status":{"created_at":"Fri Jun 15 00:47:15 +0000 2012","id":213432448762134528,"id_str":"213432448762134528","text":"I sat beside my little brother on the front porch, and I told him a story about a flower that fell in love with a star.","source":"\u003ca href=\"http:\/\/twitterrific.com\" rel=\"nofollow\"\u003eTwitterrific\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":11,"favorited":false,"retweeted":false},"contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/a0.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/si0.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/1114076851\/Brautigan_normal.jpg","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1114076851\/Brautigan_normal.jpg","profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"show_all_inline_media":false,"default_profile":true,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null}

我有几个疑问:

  • 是否需要 C# 中的 JSON 解析器来处理 JSON 消息?
  • 此 JSON 消息不包含有关推广推文的信息,我该如何获取?

【问题讨论】:

    标签: c# json c#-4.0 twitter


    【解决方案1】:

    这是Twitter's REST API 的文档。 您可以按如下方式使用它们:

    using (var wc = new WebClient())
    {
        string searchText = "kool_aid_wino";
        string json = wc.DownloadString("http://search.twitter.com/search.json?rpp=100&q="+searchText);
        dynamic dynJson = JsonConvert.DeserializeObject(json);
        foreach (var result in dynJson.results)
        {
            Console.WriteLine("{0} --> {1} : {2}\n", result.from_user, result.to_user, result.text);
        }
    }
    

    PS:你需要Json.Net(我最喜欢的json解析器)来运行上面的代码

    【讨论】:

      【解决方案2】:

      是否需要 C# 中的 JSON 解析器来处理 JSON 消息?

      嗯,从技术上讲,答案是肯定的,但我假设您是在问是否需要第 3 方。 C# 有 JavaScriptSerializer 类,只要您先定义具有适当属性的类,该类就可以获取此 JSON 并将其转换为对象。

      【讨论】:

      • 其他的呢?为什么我没有收到推文和推广推文?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-15
      • 1970-01-01
      • 1970-01-01
      • 2019-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多