简体   繁体   中英

Fetch Twitter Timeline as XML/JSON, show in Windows 8 app

I'm currently following a tutorial on how to show Twitter feeds with LINQ to XML in C#. However, seeing as Microsoft has replaced WebClient with HTTPClient , I'm unsure how to proceed on my quest of integrating this into my Windows 8 application.
The tutorial: http://www.codeproject.com/Articles/117614/How-to-query-twitter-public-status-using-LINQ-to-X

The thing is that I'm "halfway" used to DownloadStringCompleted , which I believe is not in the HTTPClient api. So after searching for a while on the async/await functionality, I mixed some of my knowledge together with some tutorials and snippets I found, but what I ended up with would not work:

    public async Task<XElement> GetXmlAsync()
    {
        var client = new HttpClient();
        var response = await client.GetAsync("http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=VladimirPutin");
        var text = response.Content.ReadAsStringAsync();
        return XElement.Parse(text.Result);

        XElement xmlTweets = XElement.Parse(text.Result);
        listboxTweetsSecond.ItemsSource = from tweet in xmlTweets.Descendants("status")
                                          select new UserTweet
                                          {
                                              UserImageSrc = tweet.Element("user").Element("profile_image_url").Value,
                                              UserMessage = tweet.Element("text").Value,
                                              UserName = tweet.Element("user").Element("screen_name").Value
                                          };

    }

(Yeah, the Twitter username is just a placeholder)
I do not need an entire code as an answer, but I'd love it if someone could point out where I should go from here, as well as what I should do in general, as this (of course) does not work (as in, it does not show anything when I run it/debug mode).

Comment out the line

return XElement.Parse(text.Result);

and it should probably work.

Having done that (ie you are no longer returning an XElement) you can probably change the method signature top return just a task.

public async Task GetXmlAsync()
{
    // method body
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM