internal static void GetFlickrUserIdFromUserName(string username, string apiKey, GetFlickrUserIdFromUserNameCallback callback)
        {
            if (_flickrUserNameCache.ContainsValue(username))
            {
                callback((from kvp in _flickrUserNameCache where kvp.Value == username select kvp.Key).FirstOrDefault());
                return;
            }

            string          query   = string.Format(CultureInfo.InvariantCulture, "http://api.flickr.com/services/rest/?method=flickr.people.findByUsername&api_key={0}&username={1}", apiKey, username);
            AsyncWebRequest request = new AsyncWebRequest();

            request.Request(new Uri(query));
            request.Result += (sender, e) =>
            {
                if (e.Status != HttpStatusCode.OK)
                {
                    callback(null);
                }

                try
                {
                    string userid = XDocument.Parse(e.Response).Element("rsp").Element("user").Attribute("nsid").Value;
                    _flickrUserNameCache[userid] = username;
                    callback(userid);
                }
                catch
                {
                    callback(null);
                }
            };
        }
Example #2
0
        internal static void GetFlickrUserIdFromUserName(string username, string apiKey, GetFlickrUserIdFromUserNameCallback callback)
        {
            if (_flickrUserNameCache.ContainsValue(username))
            {
                callback((from kvp in _flickrUserNameCache where kvp.Value == username select kvp.Key).FirstOrDefault());
                return;
            }

            string query = string.Format(CultureInfo.InvariantCulture, "http://api.flickr.com/services/rest/?method=flickr.people.findByUsername&api_key={0}&username={1}", apiKey, username);
            AsyncWebRequest request = new AsyncWebRequest();
            request.Request(new Uri(query));
            request.Result += (sender, e) =>
            {
                if (e.Status != HttpStatusCode.OK)
                {
                    callback(null);
                }

                try
                {
                    string userid = XDocument.Parse(e.Response).Element("rsp").Element("user").Attribute("nsid").Value;
                    _flickrUserNameCache[userid] = username;
                    callback(userid);
                }
                catch
                {
                    callback(null);
                }
            };
        }