Ejemplo n.º 1
0
        private void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            Flickr f = FlickrManager.GetAuthInstance();

            PhotoSearchOptions options = new PhotoSearchOptions();

            options.Tags   = SearchTextBox.Text;
            options.Extras = PhotoSearchExtras.LargeSquareUrl;

            f.PhotosSearchAsync(options, r =>
            {
                if (r.Error != null)
                {
                    Dispatcher.BeginInvoke(() =>
                    {
                        MessageBox.Show("An error occurred talking to Flickr: " + r.Error.Message);
                    });
                    return;
                }

                PhotoCollection photos = r.Result;

                Dispatcher.BeginInvoke(() =>
                {
                    ResultsListBox.ItemsSource = photos;
                });
            });
        }
Ejemplo n.º 2
0
        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            Flickr f = FlickrManager.GetInstance();

            // obtain the request token from Flickr
            f.OAuthGetRequestTokenAsync(callbackUrl, r =>
            {
                // Check if an error was returned
                if (r.Error != null)
                {
                    Dispatcher.BeginInvoke(() => { MessageBox.Show("An error occurred getting the request token: " + r.Error.Message); });
                    return;
                }

                // Get the request token
                requestToken = r.Result;

                // get Authorization url
                string url = f.OAuthCalculateAuthorizationUrl(requestToken.Token, AuthLevel.Write);
                // Replace www.flickr.com with m.flickr.com for mobile version
                // url = url.Replace("https://www.flickr.com", "http://www.flickr.com");

                // Navigate to url
                Dispatcher.BeginInvoke(() => { WebBrowser1.Navigate(new Uri(url)); });
            });
        }
Ejemplo n.º 3
0
        private void UploadButton_OnClick(object sender, RoutedEventArgs e)
        {
            var f = FlickrManager.GetAuthInstance();

            //Stream fileStream = new FileStream(_photoFilename, FileMode.Open);
            _startingMemoryUsage = DeviceStatus.ApplicationCurrentMemoryUsage;
            f.UploadPictureAsync(_photoStream, "photo.jpg", Title.Text, null, null, false, false, false, ContentType.Photo, SafetyLevel.None, HiddenFromSearch.None, UploadComplete);
        }
Ejemplo n.º 4
0
        private void WebBrowser1_Navigating(object sender, NavigatingEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("Url: " + e.Uri.AbsoluteUri);

            // if we are not navigating to the callback url then authentication is not complete.
            if (!e.Uri.AbsoluteUri.StartsWith(callbackUrl))
            {
                return;
            }

            // Get "oauth_verifier" part of the query string.
            var oauthVerifier = e.Uri.Query.Split('&')
                                .Where(s => s.Split('=')[0] == "oauth_verifier")
                                .Select(s => s.Split('=')[1])
                                .FirstOrDefault();

            if (String.IsNullOrEmpty(oauthVerifier))
            {
                MessageBox.Show("Unable to find Verifier code in uri: " + e.Uri.AbsoluteUri);
                return;
            }

            // Found verifier, so cancel navigation
            e.Cancel = true;
            WebBrowser1.Visibility = Visibility.Collapsed;

            // Obtain the access token from Flickr
            Flickr f = FlickrManager.GetInstance();

            f.OAuthGetAccessTokenAsync(requestToken, oauthVerifier, r =>
            {
                // Check if an error was returned
                if (r.Error != null)
                {
                    Dispatcher.BeginInvoke(() => MessageBox.Show("An error occurred getting the access token: " + r.Error.Message));
                    return;
                }

                OAuthAccessToken accessToken = r.Result;

                // Save the oauth token for later use
                FlickrManager.OAuthToken       = accessToken.Token;
                FlickrManager.OAuthTokenSecret = accessToken.TokenSecret;

                Dispatcher.BeginInvoke(() => MessageBox.Show("Authentication completed for user " + accessToken.FullName + ", with token " + accessToken.Token));
            });
        }