0

我想从 Twitter 帐户中获取所有朋友。我已经完成了以下代码:

        username = "username";
        password = "password";
        string url = "http://twitter.com/statuses/friends.xml";
        string user = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + ":" + password));
        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
        Friends frd;
        List<Friends> lf = new List<Friends>();

        request.Method = "POST";
        request.Credentials = new NetworkCredential(username, password);
        WebResponse response = request.GetResponse();
        StreamReader reader = new StreamReader(response.GetResponseStream());
        string responseString = reader.ReadToEnd();
        reader.Close();
        XmlDocument xmld = new XmlDocument();
        xmld.LoadXml(responseString);
        XDocument document = XDocument.Parse(responseString);

        foreach (XmlNode xmln in xmld.SelectNodes("users/user"))
        {
            frd = new Friends();
            frd.id = Convert.ToInt32(xmln["id"].InnerText);
            frd.name = xmln["name"].InnerText;
            frd.screen_name = xmln["screen_name"].InnerText;
            lf.Add(frd);
        }

但是,我得到空响应。我应该错过其中的一些东西吗?还是有其他更好的选择?

4

1 回答 1

0

不确定这是否是问题的全部,但是:

request.Method = "POST";

如果您要检索,应该是 GET。

于 2013-04-23T13:29:31.397 回答