0

我将首先说我是构建 Windows 8 应用程序的新手。我最近下载了以下 XAML-Twitter 客户端示例:

http://code.msdn.microsoft.com/windowsapps/XAML-Twitter-Client-e343d336#content

在代码中,它使用以下关键字搜索推文:

SyndicationFeed feed = await client.RetrieveFeedAsync(new Uri("http://search.twitter.com/search.rss?q=" + TweetSearch));

“TweetSearch”是一个包含关键字的字符串值。

我正在尝试更改此代码以检索和显示某个用户的所有推文,但无法使其正常工作。这是我最接近的是:

SyndicationClient client = new SyndicationClient();

//SyndicationFeed feed = await client.RetrieveFeedAsync(new Uri("https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=UserName"));

model.Tweets.Clear();

foreach (var item in feed.Items)
{
    _model.Tweets.Add(new Tweet
    {
        Name = item.Authors[0].Email,
        Message = item.Title.Text,
        Image = new BitmapImage(new Uri(item.ElementExtensions.First(element => element.NodeName == "image_link").NodeValue))});
    }
}

但我收到错误"Specified argument was out of the range of valid values."

        foreach (var item in feed.Items)
        {
            _model.Tweets.Add(new Tweet
            {
                Name = item.Authors[0].Email,
                Message = item.Title.Text,
                Image = new BitmapImage(new Uri(item.ElementExtensions.First(element => element.NodeName == "image_link").NodeValue))
            });
        }
4

1 回答 1

0

Here is documentation of GET statuses/user_timeline

You have to change the click event like this

private async void Button_Click_1(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
    SyndicationClient client = new SyndicationClient();
    SyndicationFeed feed = await client.RetrieveFeedAsync(new Uri("https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=" + SearchTerm.Text));

    _model.Tweets.Clear();

    foreach (var item in feed.Items)
    {
        _model.Tweets.Add(new Tweet
        {
            Message = item.Summary.Text
        });
    }
}

I haven't changed the data template of GridView, I used the existing one. If you want to show the user's profile picture then check the documentation of GET users/show. You have to deserliaze the response.

于 2013-04-30T06:30:34.940 回答