public async void GetPopularTagListAsync() { string timestamp = DateTimeUtils.GetTimestamp(); string nonce = Guid.NewGuid().ToString().Replace("-", null); string paramString = "oauth_nonce=" + nonce; paramString += "&oauth_consumer_key=" + consumerKey; paramString += "&oauth_signature_method=HMAC-SHA1"; paramString += "&oauth_timestamp=" + timestamp; paramString += "&oauth_version=1.0"; paramString += "&oauth_token=" + AccessToken; paramString += "&format=json&nojsoncallback=1"; paramString += "&method=flickr.tags.getHotList"; string signature = GenerateSignature("GET", AccessTokenSecret, "https://api.flickr.com/services/rest/", paramString); string requestUrl = "https://api.flickr.com/services/rest/?" + paramString + "&oauth_signature=" + signature; HttpWebResponse response = await DispatchRequest("GET", requestUrl, null).ConfigureAwait(false); using (StreamReader reader = new StreamReader(response.GetResponseStream())) { if (response.StatusCode != HttpStatusCode.OK) { HandleHTTPException(response); return; } string jsonString = await reader.ReadToEndAsync().ConfigureAwait(false); if (!IsResponseSuccess(jsonString)) return; GetPopularTagListEventArgs args = new GetPopularTagListEventArgs(); args.Response = jsonString; PopularTagListReturned.DispatchEvent(this, args); } }
private void OnPopularTagListReturned(object sender, GetPopularTagListEventArgs e) { JObject rawJson = JObject.Parse(e.Response); JObject rootJson = (JObject)rawJson["hottags"]; List<PhotoTag> result = new List<PhotoTag>(); foreach (JObject json in rootJson["tag"]) { PhotoTag tag = new PhotoTag(); tag.Name = json["_content"].ToString(); tag.Weight = int.Parse(json["score"].ToString()); result.Add(tag); } PopularTagListUpdatedEventArgs evt = new PopularTagListUpdatedEventArgs(); evt.Tags = result; PopularTagsUpdated.DispatchEvent(this, evt); }