Merhaba arkadaşlar ,
Bu makalemde sizlerle Windows Phone üzerinde nasıl twitter uygulaması yazarız ve de twitter API sini nasıl kullanırız bundan bahsediyor olacağız .
İlk olarak bir Windows Phone uygulaması oluşturalım ve de ardından Windows Phone 7.1 seçeneğini seçelim .

Projemizi oluşturduktan sonra xaml tarafında düzenleme yapalım . İşte projemizin xaml kodları :
<Grid x:Name="LayoutRoot" Background="Transparent"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> |
Görüldüğü gibi ekran da bir adet textbox ve buton ile bir listbox bulunmaktadır . Şimdi ise c# programlama dilini kullanarak Twitter isminde bir class oluşturalım ve de ilgili propertyler ile API mizi yazalım .
using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes;using Microsoft.Phone.Controls;using System.Xml.Linq;namespace TweetApp_YazilimDilleri{ public partial class MainPage : PhoneApplicationPage { // Constructor public MainPage() { InitializeComponent(); } public class Twitter { public string kullanici_adi { get; set; } public string mesaj { get; set; } public string resim { get; set; } } private void button1_Click(object sender, RoutedEventArgs e) { if (textBox1.Text != "" && textBox1.Text!="kullaniciadi..") { WebClient servis = new WebClient(); servis.DownloadStringCompleted += new DownloadStringCompletedEventHandler(servis_DownloadStringCompleted); servis.DownloadStringAsync(new Uri("http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=" + textBox1.Text)); } else { MessageBox.Show("Boş Bırakmayınız "); } } void servis_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { if (e.Error!=null) return; XElement element = XElement.Parse(e.Result); lstTweets.ItemsSource = from a in element.Descendants("status") select new Twitter { resim = a.Element("user").Element("profile_image_url").Value, mesaj = a.Element("text").Value, kullanici_adi = a.Element("user").Element("screen_name").Value }; } }} |
Gördüğünüz gibi arkadaslar Twitter class ı olusturduk ve de bu class da 3 tane property e yer verdik .
Daha sonra bu propertyleri xaml tarafında ilgili kontrollere Bind ettik . Daha sonradan ise linq ile kısa bir sorgulama yaparak Twitter API sini kullanmış olduk . Bu arada unutmadan söyleyeyim . XElement class ını kullanmak için promize System.Xml.Linq dll i nide eklemek gerekiyor . İşte sonucumuz :

Umarım faydalı olmuştur
İyi çalışmalar .
Hiç yorum yok:
Yorum Gönder