Getting BrightKite friends using C# and LINQ

 is a location aware social network.  It allows you to post notes and pictures at a specific place.  It also will write to your Twitter stream so your friends can keep up with your latest activity.

They also have an , which I had the chance to play with the other night.  Here is some very simple code that will write out a list of all your friends:

public static void ListFriends(string username, string password)

{

string url = "http://brightkite.com/me/friends.xml";

WebRequest WRequest = WebRequest.Create(url) as HttpWebRequest;

WRequest.Timeout = 10000;

WRequest.Headers.Add("Authorization",

"Basic " + Convert.ToBase64String(

Encoding.ASCII.GetBytes(username + ":" + password)));

using (HttpWebResponse response = WRequest.GetResponse as HttpWebResponse)

{

StreamReader reader = new StreamReader(response.GetResponseStream);

XElement element = XElement.Load(reader);

foreach (XElement node in element.Elements("person"))

{

string place = node.Element("place").Element("name").Value;

string person = node.Element("fullname").Value;

Console.WriteLine("{0} checked in at {1}",person,place);

}

}

}

My BrightKite = 

My Twitter = timhibbard

This article is part of the GWB Archives. Original Author: Tim Hibbard

New on Geeks with Blogs