Skip to content

Instantly share code, notes, and snippets.

@anuith
Created June 24, 2012 20:06
Show Gist options
  • Save anuith/2984706 to your computer and use it in GitHub Desktop.
Save anuith/2984706 to your computer and use it in GitHub Desktop.
Windows Phone Hackathon : Facebook & Instagram Sample - Instagram Code - Get Feed (Incompleted; continue https://gist.github.com/2984709 )
private void GetFeedAsync() {
string url = string.Format(
@"https://api.instagram.com/v1/media/popular?client_id={0}",
appid);
Uri endpointUri = new Uri(url);
WebClient webclient = new WebClient();
webclient.DownloadStringCompleted +=
new DownloadStringCompletedEventHandler(webclient_DownloadStringCompleted);
webclient.DownloadStringAsync(endpointUri);
}
private void webclient_DownloadStringCompleted(
object sender, DownloadStringCompletedEventArgs e) {
// Check for connection error
if (e.Error != null) {
MessageBox.Show("server says: " + e.Error.Message, "an error occured", MessageBoxButton.OK);
return;
}
// Parse json object from result json string
string resultString = e.Result;
JObject json = JObject.Parse(resultString);
// Check response code
int responseCode = json.SelectToken("meta.code").Value<int>();
if (responseCode != 200) {
string errorMessage =
json.SelectToken("meta.code.error_message").Value<string>();
MessageBox.Show(
"Instagram server says: " + errorMessage, "an error occured",
MessageBoxButton.OK);
}
DisplayFeed(json["data"]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment