コード例 #1
0
        // Activity stream retrieved for a user
        private void OnActivityStreamReturned(object sender, GetActivityStreamEventArgs e)
        {
            JObject rawJson = JObject.Parse(e.Response);
            JObject rootJson = (JObject)rawJson["items"];
            ActivityItemsCount = int.Parse(rootJson["total"].ToString());

            ActivityList.Clear();
            foreach (var entry in rootJson["item"])
            {
                JObject json = (JObject)entry;
                PhotoActivity activity = ActivityFactory.ActivityWithJObject(json);

                if (activity == null)
                    continue;

                if (!ActivityList.Contains(activity))
                {
                    ActivityList.Add(activity);
                }
            }

            // Dispatch event
            if (ActivityStreamUpdated != null)
                ActivityStreamUpdated(this, null);
        }
コード例 #2
0
        public async void GetActivityStreamAsync()
        {
            if (isLoadingActivityStream)
                return;

            isLoadingActivityStream = true;

            string timestamp = DateTimeUtils.GetTimestamp();
            string nonce = Guid.NewGuid().ToString().Replace("-", null);

            Dictionary<string, string> paramDict = new Dictionary<string, string>();
            paramDict["method"] = "flickr.activity.userPhotos";
            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["timeframe"] = "30d";
            paramDict["page"] = "1";
            paramDict["per_page"] = "25";

            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()))
            {
                isLoadingActivityStream = false;

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    HandleHTTPException(response);
                    return;
                }

                string jsonString = await reader.ReadToEndAsync().ConfigureAwait(false);
                if (!TryHandleResponseException(jsonString, () => { GetActivityStreamAsync(); }))
                    return;


                GetActivityStreamEventArgs args = new GetActivityStreamEventArgs();
                args.Response = jsonString;
                ActivityStreamReturned.DispatchEvent(this, args);
            }
        }