Firdous
Firdous

Reputation: 4652

Need tweets in my iOS application

Any starter material on using Twitter framework in iOS 5, I intend to view tweets from users

Upvotes: 0

Views: 802

Answers (2)

Kamleshwar
Kamleshwar

Reputation: 2997

In latest release apple provide Twitter Framework, you can refer documentation

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

And for sample source code

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

This sample demonstrates the built-in Twitter composition sheet, creating a POST request, and parsing returned data.

Upvotes: 1

Adrian Marinica
Adrian Marinica

Reputation: 2201

This is a mock-up of what you need in .NET. I'm sure you'll be able to translate it to objective-c, or whatever it is you're working in. Basically, the XML file is what you need.

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

Upvotes: 0

Related Questions