Charlie Calvert on Elvenware

Writing Code and Prose on Computers

Elvenware

WebRequests

Conduct a Twitter request for information about an IP address.

private void ButtonTwitterRequest_Click(object sender, EventArgs e)
{
    string url = @"http://api.twitter.com/1/geo/search.json?ip={0}";

    string ip = "74.125.19.104";

    RetrieveFromWeb web = new RetrieveFromWeb();
    HttpWebResponse webResponse;
              
    string result = web.GetPageFromWeb(url, ip, out webResponse);

    textBox1.Text = result;

    JavaScriptSerializer js = new JavaScriptSerializer();
    Dictionary<string, object> foo = 
    	(Dictionary<string, object>)js.DeserializeObject(result);
    Dictionary<string, object> bar = 
    	(Dictionary<string, object>)foo["result"];
    object[] spots = (object[])bar["places"];

    for (int i = 0; i < spots.Count(); i++)
    {
        listBox1.Items.Add(((Dictionary<string, object>)
        	spots[i])["full_name"]);    
    }            
}

Twitter Buttons