Example #1
0
        /// <summary>
        /// Returns the location data for a give photo.
        /// </summary>
        /// <param name="photoId">The ID of the photo to return the location information for.</param>
        /// <param name="callback">Callback method to call upon return of the response from Flickr.</param>
        public async Task<FlickrResult<PlaceInfo>> PhotosGeoGetLocationAsync(string photoId)
        {
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("method", "flickr.photos.geo.getLocation");
            parameters.Add("photo_id", photoId);

            var r = await GetResponseAsync<PhotoInfo>(
                parameters);

            FlickrResult<PlaceInfo> result = new FlickrResult<PlaceInfo>();
            result.HasError = r.HasError;
            if (result.HasError)
            {
                if (result.ErrorCode == 2)
                {
                    result.HasError = false;
                    result.Result = null;
                    result.Error = null;
                }
                else
                {
                    result.Error = r.Error;
                }
            }
            else
            {
                result.Result = r.Result.Location;
            }
            return result;
                
        }
        /// <summary>
        /// Returns the location data for a give photo.
        /// </summary>
        /// <param name="photoId">The ID of the photo to return the location information for.</param>
        /// <param name="callback">Callback method to call upon return of the response from Flickr.</param>
        public void PhotosGeoGetLocationAsync(string photoId, Action<FlickrResult<PlaceInfo>> callback)
        {
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("method", "flickr.photos.geo.getLocation");
            parameters.Add("photo_id", photoId);

            GetResponseAsync<PhotoInfo>(
                parameters,
                r =>
                {
                    FlickrResult<PlaceInfo> result = new FlickrResult<PlaceInfo>();
                    result.HasError = r.HasError;
                    if (result.HasError)
                    {
                        if (result.ErrorCode == 2)
                        {
                            result.HasError = false;
                            result.Result = null;
                            result.Error = null;
                        }
                        else
                        {
                            result.Error = r.Error;
                        }
                    }
                    else
                    {
                        result.Result = r.Result.Location;
                    }
                    callback(result);
                });
        }
Example #3
0
        /// <summary>
        /// For a given request token and verifier string return an access token.
        /// </summary>
        /// <param name="requestToken"></param>
        /// <param name="requestTokenSecret"></param>
        /// <param name="verifier"></param>
        /// <param name="callback"></param>
        public async Task<FlickrResult<OAuthAccessToken>> OAuthGetAccessTokenAsync(string requestToken, string requestTokenSecret, string verifier)
        {
            string url = "https://api.twitter.com/oauth/access_token";

            Dictionary<string, string> parameters = OAuthGetBasicParameters();

            parameters.Add("oauth_verifier", verifier);
            parameters.Add("oauth_token", requestToken);

            string sig = OAuthCalculateSignature("POST", url, parameters, requestTokenSecret);

            parameters.Add("oauth_signature", sig);

            FlickrResult<string> r = await TwitterResponder.GetDataResponseAsync(this, "POST", url, parameters);

            FlickrResult<OAuthAccessToken> result = new FlickrResult<OAuthAccessToken>();

            if (!r.HasError)
            {
                result.Result = FlickrNet.OAuthAccessToken.ParseResponse(r.Result);
            }
            else
            {
                result.HasError = r.HasError;
                result.Error = r.Error;
                result.ErrorCode = r.ErrorCode;
                result.ErrorMessage = r.ErrorMessage;
            }

            return result;

        }
Example #4
0
        /// <summary>
        /// Get an <see cref="OAuthRequestToken"/> for the given callback URL.
        /// </summary>
        /// <remarks>Specify 'oob' as the callback url for no callback to be performed.</remarks>
        /// <param name="callbackUrl">The callback Uri, or 'oob' if no callback is to be performed.</param>
        /// <param name="callback"></param>
        public void OAuthGetRequestTokenAsync(string callbackUrl, Action<FlickrResult<OAuthRequestToken>> callback)
        {
            string url = "http://www.flickr.com/services/oauth/request_token";

            Dictionary<string, string> parameters = OAuthGetBasicParameters();

            parameters.Add("oauth_callback", callbackUrl);

            string sig = OAuthCalculateSignature("POST", url, parameters, null);

            parameters.Add("oauth_signature", sig);

            FlickrResponder.GetDataResponseAsync(this, url, parameters, (r) =>
            {
                FlickrResult<OAuthRequestToken> result = new FlickrResult<OAuthRequestToken>();
                if (r.Error != null)
                {
                    if (r.Error is System.Net.WebException)
                    {
                        OAuthException ex = new OAuthException(r.Error);
                        result.Error = ex;
                    }
                    else
                    {
                        result.Error = r.Error;
                    }
                    callback(result);
                    return;
                }
                result.Result = FlickrNet.OAuthRequestToken.ParseResponse(r.Result);
                callback(result);
            });
        }
        private void FlickrRequest_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                MessageBox.Show(e.Error.Message);
            }
            else
            {
                this.FeatureSets.Remove(flickrsSet);
                FlickrResult frResult = FlickrResult.Deserialize(e.Result);
                flickrsSet = new GeoFeatureCollection("title,photoUrl,ownerName,dateTaken", "Title,Photo,Owner,Date", "title", "Flickr");

                if (frResult != null && frResult.photoPage != null && frResult.photoPage.photos != null)
                {
                    foreach (FlickrPhoto item in frResult.photoPage.photos)
                    {
                        Graphic graphic = new Graphic();
                        graphic.Geometry = (new MapPoint(item.longitude, item.latitude, new SpatialReference(4326))).GeographicToWebMercator();
                        graphic.Attributes.Add("title", item.title);
                        graphic.Attributes.Add("photoUrl", item.photoUrl);
                        graphic.Attributes.Add("ownerName", item.ownerName);
                        graphic.Attributes.Add("dateTaken", item.dateTaken);
                        graphic.Symbol = flickrSymbol;
                        graphic.MapTip = flickrTipTemplate;
                        graphicsLayer.Graphics.Add(graphic);
                        flickrsSet.Add(graphic);
                    }

                    this.FeatureSets.Add(flickrsSet);
                    this.ToggleWidgetContent(1);
                }
            }

            this.IsBusy = false;
        }
Example #6
0
        /// <summary>
        /// Get an <see cref="OAuthRequestToken"/> for the given callback URL.
        /// </summary>
        /// <remarks>Specify 'oob' as the callback url for no callback to be performed.</remarks>
        /// <param name="callbackUrl">The callback Uri, or 'oob' if no callback is to be performed.</param>
        /// <param name="callback"></param>
        public async Task<FlickrResult<OAuthRequestToken>> OAuthGetRequestTokenAsync(string callbackUrl)
        {

            string url = RequestTokenUrl; //"https://www.flickr.com/services/oauth/request_token";

            Dictionary<string, string> parameters = OAuthGetBasicParameters();

            parameters.Add("oauth_callback", callbackUrl);

            string sig = OAuthCalculateSignature("POST", url, parameters, null);

            parameters.Add("oauth_signature", sig);

            FlickrResult<string> r = await TwitterResponder.GetDataResponseAsync(this, "POST", url, parameters);

            FlickrResult<OAuthRequestToken> result = new FlickrResult<OAuthRequestToken>();

            if (!r.HasError)
            {
                result.Result = FlickrNet.OAuthRequestToken.ParseResponse(r.Result);
            }
            else
            {
                result.HasError = r.HasError;
                result.Error = r.Error;
                result.ErrorCode = r.ErrorCode;
                result.ErrorMessage = r.ErrorMessage;
            }

            return result;

        }
Example #7
0
        /// <summary>
        /// Add a note to a picture.
        /// </summary>
        /// <param name="photoId">The photo id to add the note to.</param>
        /// <param name="noteX">The X co-ordinate of the upper left corner of the note.</param>
        /// <param name="noteY">The Y co-ordinate of the upper left corner of the note.</param>
        /// <param name="noteWidth">The width of the note.</param>
        /// <param name="noteHeight">The height of the note.</param>
        /// <param name="noteText">The text in the note.</param>
        /// <param name="callback">Callback method to call upon return of the response from Flickr.</param>
        public void PhotosNotesAddAsync(string photoId, int noteX, int noteY, int noteWidth, int noteHeight, string noteText, Action<FlickrResult<string>> callback)
        {
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("method", "flickr.photos.notes.add");
            parameters.Add("photo_id", photoId);
            parameters.Add("note_x", noteX.ToString(System.Globalization.NumberFormatInfo.InvariantInfo));
            parameters.Add("note_y", noteY.ToString(System.Globalization.NumberFormatInfo.InvariantInfo));
            parameters.Add("note_w", noteWidth.ToString(System.Globalization.NumberFormatInfo.InvariantInfo));
            parameters.Add("note_h", noteHeight.ToString(System.Globalization.NumberFormatInfo.InvariantInfo));
            parameters.Add("note_text", noteText);

            GetResponseAsync<UnknownResponse>(
                parameters,
                r =>
                {
                    FlickrResult<string> result = new FlickrResult<string>();
                    result.HasError = r.HasError;
                    if (r.HasError)
                    {
                        result.Error = r.Error;
                    }
                    else
                    {
                        result.Result = r.Result.GetAttributeValue("*", "id");
                    }
                    callback(result);
                });
        }
Example #8
0
        /// <summary>
        /// Retrieve a temporary FROB from the Flickr service, to be used in redirecting the
        /// user to the Flickr web site for authentication. Only required for desktop authentication.
        /// </summary>
        /// <remarks>
        /// Pass the FROB to the <see cref="AuthCalcUrl"/> method to calculate the url.
        /// </remarks>
        /// <example>
        /// <code>
        /// string frob = flickr.AuthGetFrob();
        /// string url = flickr.AuthCalcUrl(frob, AuthLevel.Read);
        /// 
        /// // redirect the user to the url above and then wait till they have authenticated and return to the app.
        /// 
        /// Auth auth = flickr.AuthGetToken(frob);
        /// 
        /// // then store the auth.Token for later use.
        /// string token = auth.Token;
        /// </code>
        /// </example>
        /// <param name="callback">Callback method to call upon return of the response from Flickr.</param>
        public void AuthGetFrobAsync(Action<FlickrResult<string>> callback)
        {
            CheckSigned();

            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("method", "flickr.auth.getFrob");

            GetResponseAsync<UnknownResponse>(
                parameters,
                r =>
                {
                    FlickrResult<string> result = new FlickrResult<string>();
                    result.HasError = r.HasError;
                    if (r.HasError)
                    {
                        result.Error = r.Error;
                    }
                    else
                    {
                        result.Result = r.Result.GetElementValue("frob");
                    }
                    callback(result);

                });
        }
Example #9
0
        /// <summary>
        /// For a given request token and verifier string return an access token.
        /// </summary>
        /// <param name="requestToken"></param>
        /// <param name="requestTokenSecret"></param>
        /// <param name="verifier"></param>
        /// <param name="callback"></param>
        public async Task<FlickrResult<OAuthAccessToken>> OAuthGetAccessTokenAsync(string requestToken, string requestTokenSecret, string verifier)
        {
            string url = "https://www.flickr.com/services/oauth/access_token";

            Dictionary<string, string> parameters = OAuthGetBasicParameters();

            parameters.Add("oauth_verifier", verifier);
            parameters.Add("oauth_token", requestToken);

            string sig = OAuthCalculateSignature("POST", url, parameters, requestTokenSecret);

            parameters.Add("oauth_signature", sig);

            var r = await FlickrResponder.GetDataResponseAsync(this, "", url, parameters); 
            
            FlickrResult<OAuthAccessToken> result = new FlickrResult<OAuthAccessToken>();
            if (r.Error != null)
            {
                if (r.Error is System.Net.WebException)
                {
                    OAuthException ex = new OAuthException(r.Error);
                    result.Error = ex;
                }
                else
                {
                    result.Error = r.Error;
                }

                return result;
            }
            result.Result = FlickrNet.OAuthAccessToken.ParseResponse(r.Result);
            return result;

        }
Example #10
0
        public async Task <FlickrResult <PhotoCollection> > SearchUserPhotoStream(int page, int imagesPerPage)
        {
            FlickrResult <PhotoCollection> streamResult = null;

            try
            {
                var taskCompletion = new TaskCompletionSource <FlickrResult <PhotoCollection> >();

                _flickrService.GetInstance()
                .PeopleGetPhotosAsync(
                    PhotoSearchExtras.All,
                    page,
                    imagesPerPage,
                    result =>
                {
                    taskCompletion.SetResult(result);
                });

                streamResult = await taskCompletion.Task;
            }
            catch (System.Exception ex)
            {
                throw new System.Exception(ex.Message, ex);
            }

            return(streamResult);
        }
Example #11
0
        void getComplete(FlickrResult<PhotoInfo> result)
        {
            string url = result.Result.MediumUrl;
            string title = result.Result.Title;
            string desc = result.Result.Description;

            System.Diagnostics.Debug.WriteLine("got details "+url+' '+title);

            this.photopreview.Source = new BitmapImage(new Uri(url));
            this.phototitle.Text = title;
            this.photodesc.Text = desc;
        }
        private static void DownloadDataAsync(string method, string baseUrl, string data, string contentType, string authHeader, Action<FlickrResult<string>> callback)
        {
            var client = new WebClient();
            client.Encoding = System.Text.Encoding.UTF8;

            if (!string.IsNullOrEmpty(contentType)) client.Headers["Content-Type"] = contentType;
            if (!string.IsNullOrEmpty(authHeader)) client.Headers["Authorization"] = authHeader;

            if (method == "POST")
            {
                client.UploadStringCompleted += delegate(object sender, UploadStringCompletedEventArgs e)
                {
                    var result = new FlickrResult<string>();
                    if (e.Error != null)
                    {
                        result.Error = e.Error;
                        callback(result);
                        return;
                    }

                    result.Result = e.Result;
                    callback(result);
                    return;
                };

                client.UploadStringAsync(new Uri(baseUrl), data);
            }
            else
            {
                client.DownloadStringCompleted += delegate(object sender, DownloadStringCompletedEventArgs e)
                {
                    var result = new FlickrResult<string>();
                    if (e.Error != null)
                    {
                        result.Error = e.Error;
                        callback(result);
                        return;
                    }

                    result.Result = e.Result;
                    callback(result);
                    return;
                };

                client.DownloadStringAsync(new Uri(baseUrl));

            }
        }
Example #13
0
        /// <summary>
        /// Returns the url to a user's photos.
        /// </summary>
        /// <param name="userId">The NSID of the user to fetch the url for. If omitted, the calling user is assumed.</param>
        /// <param name="callback">Callback method to call upon return of the response from Flickr.</param>
        public async Task<FlickrResult<string>> UrlsGetUserPhotosAsync(string userId)
        {
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("method", "flickr.urls.getUserPhotos");
            if (userId != null && userId.Length > 0) parameters.Add("user_id", userId);

            var r = await GetResponseAsync<UnknownResponse>(parameters);
            FlickrResult<string> result = new FlickrResult<string>();
            result.Error = r.Error;
            if (!r.HasError)
            {
                result.Result = r.Result.GetAttributeValue("*", "url");
            }
            return result;
                
        }
Example #14
0
        /// <summary>
        /// Returns the url to a group's page.
        /// </summary>
        /// <param name="groupId">The NSID of the group to fetch the url for.</param>
        /// <param name="callback">Callback method to call upon return of the response from Flickr.</param>
        public async Task<FlickrResult<string>> UrlsGetGroupAsync(string groupId)
        {
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("method", "flickr.urls.getGroup");
            parameters.Add("group_id", groupId);

            var r = await GetResponseAsync<UnknownResponse>(parameters);
            
            FlickrResult<string> result = new FlickrResult<string>();
            result.Error = r.Error;
            if (!r.HasError)
            {
                result.Result = r.Result.GetAttributeValue("*", "url");
            }
            return result;
            
        }
Example #15
0
    private void GetFlickrPhotoURLsCallback(FlickrResult <PhotoCollection> result)
    {
        //perform the url collection from flickr result...
        FlickrPhotoURLs.Clear();
        var photoCollection = (PhotoCollection)result.Result;

        foreach (Photo photo in photoCollection)
        {
            flickrPhotoUrls.Add(photo.MediumUrl);
        }
        //check to see if event has any subscribers...
        if (FlickrPhotoURLsLoaded != null)
        {
            //invoke any handlers delegated...
            FlickrPhotoURLsLoaded(this, new EventArgs());
        }
    }
Example #16
0
        /// <summary>
        /// Gets the currently authenticated users default hidden from search setting.
        /// </summary>
        /// <param name="callback">Callback method to call upon return of the response from Flickr.</param>
        public async Task<FlickrResult<HiddenFromSearch>> PrefsGetHiddenAsync()
        {
            CheckRequiresAuthentication();

            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("method", "flickr.prefs.getHidden");

            var r = await GetResponseAsync<UnknownResponse>(parameters);
            
            FlickrResult<HiddenFromSearch> result = new FlickrResult<HiddenFromSearch>();
            result.Error = r.Error;
            if (!r.HasError)
            {
                result.Result = (HiddenFromSearch)int.Parse(r.Result.GetAttributeValue("*", "hidden"), System.Globalization.NumberFormatInfo.InvariantInfo);
            }
            return result;
            
        }
        /// <summary>
        /// Handles on Frob reply
        /// <summary>

        void onReplyFrob(FlickrResult<String> result)
        {
            if (result.HasError)
            {
                MessageBox.Show(result.Error.Message);
            }
            else
            {
                frob = result.Result;
                MessageBox.Show(frob);

                string url = flickr.AuthCalcUrl(frob, FlickrNet.AuthLevel.Write);
                Uri uri = new Uri(url);
                container.Children.Add(_webBrowser);
                _webBrowser.Navigate(uri);           

            }
        }
Example #18
0
        /// <summary>
        /// Get the tag list for a given photo.
        /// </summary>
        /// <param name="photoId">The id of the photo to return tags for.</param>
        /// <param name="callback">Callback method to call upon return of the response from Flickr.</param>
        public async Task<FlickrResult<Collection<PhotoInfoTag>>> TagsGetListPhotoAsync(string photoId)
        {
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("method", "flickr.tags.getListPhoto");
            parameters.Add("api_key", apiKey);
            parameters.Add("photo_id", photoId);

            var r = await GetResponseAsync<PhotoInfo>(parameters);
            
            FlickrResult<Collection<PhotoInfoTag>> result = new FlickrResult<Collection<PhotoInfoTag>>();
            result.Error = r.Error;
            if (!r.HasError)
            {
                result.Result = r.Result.Tags;
            }
            return result;
            
        }
Example #19
0
        /// <summary>
        /// Returns the url to a group's page.
        /// </summary>
        /// <param name="groupId">The NSID of the group to fetch the url for.</param>
        /// <param name="callback">Callback method to call upon return of the response from Flickr.</param>
        public void UrlsGetGroupAsync(string groupId, Action<FlickrResult<string>> callback)
        {
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("method", "flickr.urls.getGroup");
            parameters.Add("group_id", groupId);

            GetResponseAsync<UnknownResponse>(
                parameters,
                r =>
                {
                    FlickrResult<string> result = new FlickrResult<string>();
                    result.Error = r.Error;
                    if (!r.HasError)
                    {
                        result.Result = r.Result.GetAttributeValue("*", "url");
                    }
                    callback(result);
                });
        }
Example #20
0
        /// <summary>
        /// Returns the url to a user's photos.
        /// </summary>
        /// <param name="userId">The NSID of the user to fetch the url for. If omitted, the calling user is assumed.</param>
        /// <param name="callback">Callback method to call upon return of the response from Flickr.</param>
        public void UrlsGetUserPhotosAsync(string userId, Action<FlickrResult<string>> callback)
        {
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("method", "flickr.urls.getUserPhotos");
            if (userId != null && userId.Length > 0) parameters.Add("user_id", userId);

            GetResponseAsync<UnknownResponse>(
                parameters,
                r =>
                {
                    FlickrResult<string> result = new FlickrResult<string>();
                    result.Error = r.Error;
                    if (!r.HasError)
                    {
                        result.Result = r.Result.GetAttributeValue("*", "url");
                    }
                    callback(result);
                });
        }
Example #21
0
        private void UploadComplete(FlickrResult <string> flickrResult)
        {
            if (flickrResult.HasError)
            {
                Dispatcher.BeginInvoke(() => MessageBox.Show("An error occurred uploading: " +
                                                             flickrResult.ErrorMessage));
            }
            else
            {
                var currentMemoryUsage = DeviceStatus.ApplicationCurrentMemoryUsage;
                var totalMemoryUsage   = currentMemoryUsage - _startingMemoryUsage;

                Debug.WriteLine("Start Memory: " + (_startingMemoryUsage / 1024 / 1024));
                Debug.WriteLine("Current Memory: " + (currentMemoryUsage / 1024 / 1024));
                Debug.WriteLine("Total Memory: " + (totalMemoryUsage / 1024 / 1024));
                Dispatcher.BeginInvoke(
                    () => MessageBox.Show("Photo uploaded successfully. Memory increase = " + totalMemoryUsage));
            }
        }
Example #22
0
        /// <summary>
        /// Returns a place based on the input latitude and longitude.
        /// </summary>
        /// <param name="latitude">The latitude, between -180 and 180.</param>
        /// <param name="longitude">The longitude, between -90 and 90.</param>
        /// <param name="accuracy">The level the locality will be for.</param>
        /// <param name="callback">Callback method to call upon return of the response from Flickr.</param>
        public async Task<FlickrResult<Place>> PlacesFindByLatLonAsync(double latitude, double longitude, GeoAccuracy accuracy)
        {
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("method", "flickr.places.findByLatLon");
            parameters.Add("lat", latitude.ToString(System.Globalization.NumberFormatInfo.InvariantInfo));
            parameters.Add("lon", longitude.ToString(System.Globalization.NumberFormatInfo.InvariantInfo));
            if (accuracy != GeoAccuracy.None) parameters.Add("accuracy", ((int)accuracy).ToString(System.Globalization.NumberFormatInfo.InvariantInfo));

            var r = await GetResponseAsync<PlaceCollection>(parameters);
                
            FlickrResult<Place> result = new FlickrResult<Place>();
            result.Error = r.Error;
            if (!r.HasError)
            {
                result.Result = r.Result[0];
            }
            return result;

        }
        /// <summary>
        /// Gets the currently authenticated users default hidden from search setting.
        /// </summary>
        /// <param name="callback">Callback method to call upon return of the response from Flickr.</param>
        public void PrefsGetHiddenAsync(Action<FlickrResult<HiddenFromSearch>> callback)
        {
            CheckRequiresAuthentication();

            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("method", "flickr.prefs.getHidden");

            GetResponseAsync<UnknownResponse>(
                parameters,
                r =>
                {
                    FlickrResult<HiddenFromSearch> result = new FlickrResult<HiddenFromSearch>();
                    result.Error = r.Error;
                    if (!r.HasError)
                    {
                        result.Result = (HiddenFromSearch)int.Parse(r.Result.GetAttributeValue("*", "hidden"), System.Globalization.NumberFormatInfo.InvariantInfo);
                    }
                    callback(result);
                });
        }
        /// <summary>
        /// For a given request token and verifier string return an access token.
        /// </summary>
        /// <param name="requestToken"></param>
        /// <param name="requestTokenSecret"></param>
        /// <param name="verifier"></param>
        /// <param name="callback"></param>
        public void OAuthGetAccessTokenAsync(string requestToken, string requestTokenSecret, string verifier, Action<FlickrResult<OAuthAccessToken>> callback)
        {
            CheckApiKey();

            #if SILVERLIGHT
            string url = "https://api.flickr.com/services/oauth/access_token";
            #else
            string url = "https://www.flickr.com/services/oauth/access_token";
            #endif

            Dictionary<string, string> parameters = OAuthGetBasicParameters();

            parameters.Add("oauth_verifier", verifier);
            parameters.Add("oauth_token", requestToken);

            string sig = OAuthCalculateSignature("POST", url, parameters, requestTokenSecret);

            parameters.Add("oauth_signature", sig);

            FlickrResponder.GetDataResponseAsync(this, url, parameters, (r) =>
                {
                    var result = new FlickrResult<OAuthAccessToken>();
                    if (r.Error != null)
                    {
                        if (r.Error is System.Net.WebException)
                        {
                            var ex = new OAuthException(r.Error);
                            result.Error = ex;
                        }
                        else
                        {
                            result.Error = r.Error;
                        }

                        callback(result);
                        return;
                    }
                    result.Result = FlickrNet.OAuthAccessToken.ParseResponse(r.Result);
                    callback(result);
                });
        }
Example #25
0
        /// <summary>
        /// Returns a place based on the input latitude and longitude.
        /// </summary>
        /// <param name="latitude">The latitude, between -180 and 180.</param>
        /// <param name="longitude">The longitude, between -90 and 90.</param>
        /// <param name="accuracy">The level the locality will be for.</param>
        /// <param name="callback">Callback method to call upon return of the response from Flickr.</param>
        public void PlacesFindByLatLonAsync(double latitude, double longitude, GeoAccuracy accuracy, Action<FlickrResult<Place>> callback)
        {
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("method", "flickr.places.findByLatLon");
            parameters.Add("lat", latitude.ToString(System.Globalization.NumberFormatInfo.InvariantInfo));
            parameters.Add("lon", longitude.ToString(System.Globalization.NumberFormatInfo.InvariantInfo));
            if (accuracy != GeoAccuracy.None) parameters.Add("accuracy", ((int)accuracy).ToString(System.Globalization.NumberFormatInfo.InvariantInfo));

            GetResponseAsync<PlaceCollection>(
                parameters,
                r =>
                {
                    FlickrResult<Place> result = new FlickrResult<Place>();
                    result.Error = r.Error;
                    if (!r.HasError)
                    {
                        result.Result = r.Result[0];
                    }
                    callback(result);
                });
        }
Example #26
0
        /// <summary>
        /// Get a list of current 'Pandas' supported by Flickr.
        /// </summary>
        /// <returns>An array of panda names.</returns>
        public async Task<FlickrResult<string[]>> PandaGetListAsync()
        {
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("method", "flickr.panda.getList");

            var r = await GetResponseAsync<UnknownResponse>(parameters);
                
            FlickrResult<string[]> result = new FlickrResult<string[]>();
            result.HasError = r.HasError;
            if (r.HasError)
            {
                result.Error = r.Error;
            }
            else
            {
                result.Result = r.Result.GetElementArray("panda");
            }
            return result;
            

        }
Example #27
0
        /// <summary>
        /// Adds a new comment to a photo.
        /// </summary>
        /// <param name="photoId">The ID of the photo to add the comment to.</param>
        /// <param name="commentText">The text of the comment. Can contain some HTML.</param>
        /// <param name="callback">Callback method to call upon return of the response from Flickr.</param>
        public async Task<FlickrResult<string>> PhotosCommentsAddCommentAsync(string photoId, string commentText)
        {
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("method", "flickr.photos.comments.addComment");
            parameters.Add("photo_id", photoId);
            parameters.Add("comment_text", commentText);

            var r = await GetResponseAsync<UnknownResponse>(parameters);
            FlickrResult<string> result = new FlickrResult<string>();
            result.HasError = r.HasError;
            if (r.HasError)
            {
                result.Error = r.Error;
            }
            else
            {
                result.Result = r.Result.GetAttributeValue("*", "id");
            }
            return result;

        }
Example #28
0
        /// <summary>
        /// Get a list of current 'Pandas' supported by Flickr.
        /// </summary>
        /// <returns>An array of panda names.</returns>
        public void PandaGetListAsync(Action<FlickrResult<string[]>> callback)
        {
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("method", "flickr.panda.getList");

            GetResponseAsync<UnknownResponse>(
                parameters,
                r =>
                {
                    FlickrResult<string[]> result = new FlickrResult<string[]>();
                    result.HasError = r.HasError;
                    if (r.HasError)
                    {
                        result.Error = r.Error;
                    }
                    else
                    {
                        result.Result = r.Result.GetElementArray("panda");
                    }
                    callback(result);
                });
        }
        /// <summary>
        /// Adds a new comment to a photoset.
        /// </summary>
        /// <param name="photosetId">The ID of the photoset to add the comment to.</param>
        /// <param name="commentText">The text of the comment. Can contain some HTML.</param>
        /// <param name="callback">Callback method to call upon return of the response from Flickr.</param>
        public void PhotosetsCommentsAddCommentAsync(string photosetId, string commentText, Action<FlickrResult<string>> callback)
        {
            var parameters = new Dictionary<string, string>();
            parameters.Add("method", "flickr.photosets.comments.addComment");
            parameters.Add("photoset_id", photosetId);
            parameters.Add("comment_text", commentText);

            GetResponseAsync<UnknownResponse>(
                parameters,
                r =>
                {
                    var result = new FlickrResult<string>();
                    result.HasError = r.HasError;
                    if (r.HasError)
                        result.Error = r.Error;
                    else
                    {
                        result.Result = r.Result.GetAttributeValue("*", "id");
                    }
                    callback(result);
                });
        }
Example #30
0
        public async void Comments(string id, Action <IEnumerable <Comment>, Exception> callback)
        {
            var f = GetFlickr();

            var taskResult = await Task.Run <FlickrResult <PhotoCommentCollection> >(() =>
            {
                var result = new FlickrResult <PhotoCommentCollection>();
                try
                {
                    result.Result = f.PhotosCommentsGetList(id);
                }
                catch (Exception ex)
                {
                    result.HasError     = true;
                    result.ErrorMessage = ex.Message;
                    result.Error        = ex;
                }
                return(result);
            });

            if (taskResult.HasError)
            {
                callback(null, taskResult.Error);
                return;
            }

            var comments = (from r in taskResult.Result
                            select new Comment
            {
                Id = r.CommentId,
                Body = r.CommentHtml,
                UserId = r.AuthorUserId,
                UserName = r.AuthorUserName,
                Url = r.Permalink
            });

            callback(comments, null);
        }
Example #31
0
        public void OnUploadCompleted(FlickrResult<string> flickrResult)
        {
            _asyncUploadSettings.InputStream.Close();
            _asyncUploadSettings.InputStream = null;

            var executeFlickrUploaderWorkflowMessage = _asyncUploadSettings.Message;

            if (flickrResult.Error != null)
            {
                var webException = (WebException)flickrResult.Error;
                var response = webException.Response;
                var responseBody = string.Empty;

                if (response != null)
                {
                    if (response.ContentLength > 0)
                    {
                        using (var stream = response.GetResponseStream())
                        {
                            using (var reader = new StreamReader(stream))
                            {
                                responseBody = reader.ReadToEnd().Trim();
                            }
                        }
                    }
                }
            }

            var executedFlickrUploaderWorkflowMessage = new ExecutedFlickrUploaderWorkflowMessage
            {
                CorrelationId = executeFlickrUploaderWorkflowMessage.CorrelationId,
                Cancelled = flickrResult.HasError && flickrResult.Error is OperationCanceledException,
                Error = flickrResult.Error
            };

            var bus = BusDriver.Instance.GetBus(FlickrUploaderService.BusName);
            bus.Publish(executedFlickrUploaderWorkflowMessage);
        }
Example #32
0
        /// <summary>
        /// Retrieve a temporary FROB from the Flickr service, to be used in redirecting the
        /// user to the Flickr web site for authentication. Only required for desktop authentication.
        /// </summary>
        /// <remarks>
        /// Pass the FROB to the <see cref="AuthCalcUrl"/> method to calculate the url.
        /// </remarks>
        /// <example>
        /// <code>
        /// string frob = flickr.AuthGetFrob();
        /// string url = flickr.AuthCalcUrl(frob, AuthLevel.Read);
        /// 
        /// // redirect the user to the url above and then wait till they have authenticated and return to the app.
        /// 
        /// Auth auth = flickr.AuthGetToken(frob);
        /// 
        /// // then store the auth.Token for later use.
        /// string token = auth.Token;
        /// </code>
        /// </example>
        /// <param name="callback">Callback method to call upon return of the response from Flickr.</param>
        public async Task<FlickrResult<string>> AuthGetFrobAsync()
        {
            CheckSigned();

            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("method", "flickr.auth.getFrob");

            var r = await GetResponseAsync<UnknownResponse>(parameters);
            
            FlickrResult<string> result = new FlickrResult<string>();
            result.HasError = r.HasError;
            if (r.HasError)
            {
                result.Error = r.Error;
            }
            else
            {
                result.Result = r.Result.GetElementValue("frob");
            }
            return result;

            

        }
Example #33
0
        public async void OnSearchCommandAsync()
        {
            // if flickrTask already running, prompt user
            if (flickrTask != null &&
                flickrTask.Status != TaskStatus.RanToCompletion)
            {
                var result = MessageBox.Show(
                    "Cancel the current Flickr search?",
                    "Sure?", MessageBoxButton.YesNo,
                    MessageBoxImage.Question);

                // determine whether user wants to cancel prior search
                if (result == MessageBoxResult.No)
                {
                    return;
                }
                else
                {
                    flickrClient.CancelAsync(); // cancel current search
                }
            } // end if

            // Flickr's web service URL for searches
            var flickrURL = string.Format("https://api.flickr.com/services" +
                                          "/rest/?method=flickr.photos.search&api_key={0}&tags={1}" +
                                          "&tag_mode=all&per_page=500&privacy_filter=1", KEY,
                                          Search.Replace(" ", ","));

            //DataSource = null; // remove prior data source
            SearchList.Clear(); // clear imagesListBox
            Photo = null;       // clear pictureBox
            FlickrResult loading = new FlickrResult()
            {
                Title = "Loading..."
            };

            SearchList.Add(loading); // display Loading...

            try
            {
                // invoke Flickr web service to search Flick with user's tags
                flickrTask =
                    flickrClient.DownloadStringTaskAsync(flickrURL);

                // await flickrTask then parse results with XDocument and LINQ
                XDocument flickrXML = XDocument.Parse(await flickrTask);

                // gather information on all photos
                var flickrPhotos =
                    (from photo in flickrXML.Descendants("photo")
                     let id = photo.Attribute("id").Value
                              let title = photo.Attribute("title").Value
                                          let secret = photo.Attribute("secret").Value
                                                       let server = photo.Attribute("server").Value
                                                                    let farm = photo.Attribute("farm").Value
                                                                               select new FlickrResult
                {
                    Title = title,
                    URL = string.Format(
                        "http://farm{0}.staticflickr.com/{1}/{2}_{3}.jpg",
                        farm, server, id, secret)
                }).ToList();

                _searchList.Clear(); // clear imagesListBox

                //add result into the list
                foreach (FlickrResult fr in flickrPhotos)
                {
                    _searchList.Add(fr);
                }

                // if there were no matching results
                if (_searchList.Count == 0)
                {
                    FlickrResult noMatch = new FlickrResult()
                    {
                        Title = "No matching"
                    };
                    _searchList.Add(noMatch);
                }
            } // end try
            catch (WebException)
            {
                // check whether Task failed
                if (flickrTask.Status == TaskStatus.Faulted)
                {
                    MessageBox.Show("Unable to get results from Flickr",
                                    "Flickr Error", MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                }
                SearchList.Clear(); // clear imagesListBox
                FlickrResult error = new FlickrResult()
                {
                    Title = "Error matching"
                };
                _searchList.Add(error);
            } // end catch
        }
 void getPhotocollection(FlickrResult<PhotoCollection> collection)
 {
     // photo collection
 }
 /// <summary>
 /// handles after getting accessing token
 /// <summary>
 void onReplyAccessToken(FlickrResult<Auth> auth)
 {
     if (auth.HasError != true)
     {
         _flickrAccessToken = auth.Result.Token;
         MessageBox.Show(_flickrAccessToken);
         //flickr.PeopleGetPhotosAsync(getPhotocollection);
         _webBrowser.Visibility = System.Windows.Visibility.Collapsed;
         //callLoginReturnFunction();
     }           
 }
Example #36
0
        /// <summary>
        /// Get the tag list for a given photo.
        /// </summary>
        /// <param name="photoId">The id of the photo to return tags for.</param>
        /// <param name="callback">Callback method to call upon return of the response from Flickr.</param>
        public void TagsGetListPhotoAsync(string photoId, Action<FlickrResult<Collection<PhotoInfoTag>>> callback)
        {
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters.Add("method", "flickr.tags.getListPhoto");
            parameters.Add("api_key", apiKey);
            parameters.Add("photo_id", photoId);

            GetResponseAsync<PhotoInfo>(
                parameters,
                r =>
                {
                    FlickrResult<Collection<PhotoInfoTag>> result = new FlickrResult<Collection<PhotoInfoTag>>();
                    result.Error = r.Error;
                    if (!r.HasError)
                    {
                        result.Result = r.Result.Tags;
                    }
                    callback(result);
                });
        }
Example #37
0
        private static void DownloadDataAsync(string method, string baseUrl, string data, string contentType,
                                              string authHeader, Action <FlickrResult <string> > callback)
        {
#if NETFX_CORE
            var client = new System.Net.Http.HttpClient();
            if (!String.IsNullOrEmpty(contentType))
            {
                client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", contentType);
            }
            if (!String.IsNullOrEmpty(authHeader))
            {
                client.DefaultRequestHeaders.Add("Authorization", authHeader);
            }

            if (method == "POST")
            {
                var content       = client.PostAsync(baseUrl, new System.Net.Http.StringContent(data, System.Text.Encoding.UTF8, contentType)).Result.Content;
                var stringContent = content as System.Net.Http.StringContent;
                var result        = new FlickrResult <string> {
                    Result = content.ReadAsStringAsync().Result
                };
                callback(result);
            }
            else
            {
                var content = client.GetStringAsync(baseUrl).Result;
                var result  = new FlickrResult <string> {
                    Result = content
                };
                callback(result);
            }
#else
            var client = new WebClient();
            if (!String.IsNullOrEmpty(contentType))
            {
                client.Headers["Content-Type"] = contentType;
            }
            if (!String.IsNullOrEmpty(authHeader))
            {
                client.Headers["Authorization"] = authHeader;
            }

            if (method == "POST")
            {
                client.UploadStringCompleted += delegate(object sender, UploadStringCompletedEventArgs e)
                {
                    var result = new FlickrResult <string>();
                    if (e.Error != null)
                    {
                        result.Error = e.Error;
                        callback(result);
                        return;
                    }

                    result.Result = e.Result;
                    callback(result);
                    return;
                };

                client.UploadStringAsync(new Uri(baseUrl), data);
            }
            else
            {
                client.DownloadStringCompleted += delegate(object sender, DownloadStringCompletedEventArgs e)
                {
                    var result = new FlickrResult <string>();
                    if (e.Error != null)
                    {
                        result.Error = e.Error;
                        callback(result);
                        return;
                    }

                    result.Result = e.Result;
                    callback(result);
                    return;
                };

                client.DownloadStringAsync(new Uri(baseUrl));
            }
#endif
        }
Example #38
0
        public async void Search(ImageSearchQuery query, Action <IEnumerable <Image>, Exception> callback)
        {
            if (_cache != null && _cache.IsCached(query.ToString()))
            {
                callback(_cache.GetCache(query.ToString()), null);
            }

            var f = GetFlickr();

            PhotoSearchOptions o = new PhotoSearchOptions();

            if (query.UserOnly)
            {
                o.Username = token.Username;
            }

            o.Extras    = PhotoSearchExtras.AllUrls | PhotoSearchExtras.Description | PhotoSearchExtras.OwnerName;
            o.SortOrder = PhotoSearchSortOrder.Relevance;

            if (query.Tags != null && query.Tags.Count > 0)
            {
                o.Tags = String.Join(" ", query.Tags);
            }

            /*
             * f.PhotosSearchAsync(o, result => {
             *
             *  if (result.HasError)
             *  {
             *      callback(null, new Exception(result.ErrorMessage));
             *  }
             *
             *  var a = (from r in result.Result select new Image { Title = r.Title, Url = r.OriginalUrl }).Take(20);
             *  callback(a, null);
             * });
             */

            var taskResult = await Task.Run <FlickrResult <PhotoCollection> >(() =>
            {
                var result = new FlickrResult <PhotoCollection>();
                try
                {
                    result.Result = f.PhotosSearch(o);
                }
                catch (Exception ex)
                {
                    result.HasError     = true;
                    result.ErrorMessage = ex.Message;
                    result.Error        = ex;
                }
                return(result);
            });

            if (taskResult.HasError)
            {
                callback(null, taskResult.Error);
                return;
            }

            var images = (from r in taskResult.Result
                          select new Image
            {
                Id = r.PhotoId,
                Title = r.Title,
                Url = r.LargeUrl,
                Thumbnail = r.ThumbnailUrl,
                Description = r.Description + string.Join(" ", r.Tags.ToArray <string>())
            });

            _cache.AddCache(query.ToString(), images);
            callback(images, null);
        }