我正在尝试用“Windows”这个词发一些推文
C#:
using System;
using System.Net;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Xml.Linq;
namespace WpfApplication1 {
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
}
public class Tweet {
public String Content { get; set; }
public String Image { get; set; }
}
private void Button_Click(object sender, RoutedEventArgs e) {
Results();
}
public static List<Tweet> Results() {
using (WebClient wc = new WebClient()) {
WebClient client = new WebClient();
XDocument doc = XDocument.Load(string.Format("https://api.twitter.com/1.1/search/tweets.json?q=%23windows"));
XNamespace ns = "http://www.w3.org/2005/Atom";
List<Tweet> tweets = (from item in doc.Descendants(ns + "entry")
select new Tweet {
Content = item.Elements(ns + "content").ToString(),
Image = (from XElement x in item.Descendants(ns + "link")
where x.Attribute("type").Value == "image/png"
select x.Attribute("href").Value).First()
}).ToList();
return tweets;
}
}
}
}
XAML:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<StackPanel>
<Button
Content="Refresh"
Click="Button_Click"></Button>
<ListBox x:Name="list"></ListBox>
</StackPanel>
</Grid>
</Window>
有什么问题?