从c#中的twitter帐户获取好友列表

时间:2013-04-23 06:46:58

标签: c# twitter

我希望从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);
        }

但是,我得到了无响应。 我应该错过什么吗? 还是其他更好的选择?

1 个答案:

答案 0 :(得分:0)

不确定这是否是所有问题,但是:

request.Method = "POST";

如果要检索,应该是GET。