// User info returned private void OnUserInfoReturned(object sender, GetUserInfoEventArgs e) { JObject json = JObject.Parse(e.Response); User user = UserFactory.UserWithUserInfoJObject(json); // Dispatch event UserInfoUpdatedEventArgs evt = new UserInfoUpdatedEventArgs(); evt.UserId = e.UserId; UserInfoUpdated.DispatchEvent(this, evt); }
public async void GetUserInfoAsync(string userId) { if (userInfoFetchingQueue.Contains(userId)) return; userInfoFetchingQueue.Add(userId); string timestamp = DateTimeUtils.GetTimestamp(); string nonce = Guid.NewGuid().ToString().Replace("-", null); Dictionary<string, string> paramDict = new Dictionary<string, string>(); paramDict["method"] = "flickr.people.getInfo"; paramDict["format"] = "json"; paramDict["nojsoncallback"] = "1"; paramDict["oauth_consumer_key"] = consumerKey; paramDict["oauth_nonce"] = nonce; paramDict["oauth_signature_method"] = "HMAC-SHA1"; paramDict["oauth_timestamp"] = timestamp; paramDict["oauth_token"] = AccessToken; paramDict["oauth_version"] = "1.0"; paramDict["user_id"] = UrlHelper.Encode(userId); string paramString = GenerateParamString(paramDict); 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(userInfoFetchingQueue.Contains(userId)) userInfoFetchingQueue.Remove(userId); if (response.StatusCode != HttpStatusCode.OK) { HandleHTTPException(response); return; } string jsonString = await reader.ReadToEndAsync().ConfigureAwait(false); if (!TryHandleResponseException(jsonString, () => { GetUserInfoAsync(userId); })) return; GetUserInfoEventArgs args = new GetUserInfoEventArgs(); args.UserId = userId; args.Response = jsonString; UserInfoReturned.DispatchEvent(this, args); } }