【问题标题】:Need tweets in my iOS application在我的 iOS 应用程序中需要推文
【发布时间】:2012-02-06 08:28:05
【问题描述】:

任何关于在 iOS 5 中使用 Twitter 框架的入门资料,我打算查看来自用户的推文

【问题讨论】:

  • 这个问题有什么问题吗?

标签: ios ios5 twitter


【解决方案1】:

苹果最新发布的Twitter框架,可以参考文档

https://developer.apple.com/library/ios/#documentation/Twitter/Reference/TwitterFrameworkReference/_index.html

对于示例源代码

https://developer.apple.com/library/ios/#samplecode/Tweeting/Introduction/Intro.html#//apple_ref/doc/uid/DTS40011191

此示例演示了内置的 Twitter 组合表、创建 POST 请求以及解析返回的数据。

【讨论】:

    【解决方案2】:

    这是您在 .NET 中所需的模型。我相信你可以将它翻译成 Objective-c,或者你正在使用的任何东西。基本上,XML 文件就是你所需要的。

    string userName;
    WebClient client;
    XDocument document;
    ObservableCollection<Tweet> tweetList; 
    
    tweetList = new ObservableCollection<Tweet>();
    client = new WebClient(); 
    client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
    client.DownloadStringAsync(new Uri("http://twitter.com/statuses/user_timeline/" + userName + ".xml"));
    
    void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
            {
                if (e.Error == null)
                {
                    document = XDocument.Parse(e.Result); 
    
                    foreach (XElement tweet in document.Descendants("status"))
                    {
                        Tweet temp = new Tweet();
                        temp.Name = tweet.Element("user").Element("name").Value; 
                        temp.Image = tweet.Element("user").Element("profile_image_url").Value; 
                        temp.Text = tweet.Element("text").Value;
                        temp.Date = tweet.Element("created_at").Value.Substring(0, 11); 
                        tweetList.Add(temp);
                    }
                }
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-06
      • 2018-05-03
      • 1970-01-01
      • 2012-07-02
      • 2011-12-13
      • 1970-01-01
      相关资源
      最近更新 更多