The RSS Blog

News and commentary from the cross-platform RSS and OPML community.

Continuing to play with the twitter API. See Part Un.

Last couple days, I made a new C# program to find ppl I'm following on Twitter that didn't follow me back. I, of course, unfollowed them.

I had to cache my friends XML, since the 150 call per hour rate limit, made it impossible to run once. The code follows. Hope you like and re-use.

        static string userid = "137692493";
        static void FindNoFollows()
        {
            string s = string.Format("https://api.twitter.com/1/friends/ids.xml?screen_name={0}", "talkSportscom");
            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            if (!System.IO.File.Exists("ids.xml"))
            {
                doc.Load(s);
            }
            else
            {
                doc.Load("ids.xml");
            }

            foreach (System.Xml.XmlElement e in doc.SelectNodes("//id"))
            {
                try
                {
                    if (e.HasAttribute("done"))
                    {
                        continue;
                    }
                    e.SetAttribute("done", "true");
                    doc.Save("ids.xml");

                    // need to sleep 30 seconds between calls to avoid 150 rate limit per hour
                    //System.Threading.Thread.Sleep(30 * 1000);

                    s = string.Format("https://api.twitter.com/1/friends/ids.xml?user_id={0}", e.InnerText);
                    System.Xml.XmlDocument d = new System.Xml.XmlDocument();
                    d.Load(s);

                    System.Console.WriteLine(d.OuterXml);

                    System.Xml.XmlElement dt = (System.Xml.XmlElement)d.SelectSingleNode(
                        string.Format("//id[text()='{0}']", userid));
                    if (dt != null)
                    {
                        continue;
                    }

                    s = string.Format("https://api.twitter.com/1/users/lookup.xml?user_id={0}", e.InnerText);
                    d = new System.Xml.XmlDocument();
                    d.Load(s);
                    dt = (System.Xml.XmlElement)d.SelectSingleNode("//screen_name");

                    System.Diagnostics.Process.Start(string.Format("http://twitter.com/#!/{0}", dt.InnerText));
                }
                catch
                {
                    break;
                }

            }
        }
Reader Comments Subscribe
Type "339":