AuthGetToken() public method

After the user has authenticated your application on the flickr web site call this method with the FROB (either stored from AuthGetFrob or returned in the URL from the Flickr web site) to get the users token.
public AuthGetToken ( string frob ) : Auth
frob string The string containing the FROB.
return Auth
Exemplo n.º 1
0
        public void Login()
        {
            // Create Flickr instance
            m_flickr = new Flickr(API_KEY, SECRET);

            m_frob = m_flickr.AuthGetFrob();

            string flickrUrl = m_flickr.AuthCalcUrl(m_frob, AuthLevel.Write);

            // The following line will load the URL in the users default browser.
            System.Diagnostics.Process.Start(flickrUrl);

            bool bIsAuthorized = false;
            m_auth = new Auth();

            // do nothing until flickr authorizes.
            while (!bIsAuthorized)
            {
                try
                {
                    m_auth = m_flickr.AuthGetToken(m_frob);
                    m_flickr.AuthToken = m_auth.Token;
                    bIsAuthorized = true;
                }
                catch (FlickrException ex)
                {
                    //TODO
                    string s = ex.Message;
                }
            }
        }
Exemplo n.º 2
0
 private void buttonStart_Click(object sender, EventArgs e)
 {
     // Create Flickr instance
     Flickr flickr = new Flickr(Program.ApiKey, Program.SharedSecret);
     try
     {
         // use the temporary Frob to get the authentication
         Auth auth = flickr.AuthGetToken(Program.tempFrob);
         // Store this Token for later usage,
         // or set your Flickr instance to use it.
         string info = "Authentification réussie\n" +
             "Utilisateur identifié: " + auth.User.UserName + "\n" +
             "L'identifiant pour cette session est " + auth.Token + "\n";
         Program.AuthToken = auth.Token;
         Program.Username = auth.User.UserName;
         MessageBox.Show(info, "Identification Flickr",
           MessageBoxButtons.OK, MessageBoxIcon.Information);
         Program.WriteConfig();
         Hide();
         var main_window = new MainForm();
         main_window.Show();
     }
     catch (FlickrException ex)
     {
         // If user did not authenticate your application
         // then a FlickrException will be thrown.
         string info = "L'authentification a échoué:\n" + ex.Message;
         MessageBox.Show(info, "Identification Flickr",
           MessageBoxButtons.OK, MessageBoxIcon.Error);
         // Quit application
         Application.Exit();
     }
 }
Exemplo n.º 3
0
 private void completedAuthWorker_DoWork(object sender, DoWorkEventArgs e)
 {
     while (!e.Cancel)
     {
         try
         {
             FlickrNet.Auth token = _proxy.AuthGetToken(this.Frob);
             if (token == null)
             {
                 Thread.Sleep(2000);
             }
             else
             {
                 e.Result = token.Token;
                 break;
             }
         }
         catch (FlickrNet.FlickrApiException ex)
         {
             if (ex.Code == 108)
             {
             }
         }
     }
 }
Exemplo n.º 4
0
 protected virtual void OnCompleteBtnClicked(object sender, EventArgs e)
 {
     try {
         Auth auth = flickr.AuthGetToken(Frob);
         AuthToken = auth.Token;
         Username  = auth.User.Username;
         flickr    = new FlickrNet.Flickr(ApiKey, ApiSecret, AuthToken);
         SetBtnStateComplete();
     } catch (FlickrNet.FlickrException ex) {
         Console.Error.WriteLine(ex);
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// this method will get our Flickr Token and return it as an object
 /// </summary>
 /// <param name="flickrFrob">string</param>
 /// <returns>Flickr Token as an Object</returns>
 public string GetFlickrToken(string flickrFrob)
 {
     try
     {
         Auth auth = flickr.AuthGetToken(flickrFrob);
         flickr.AuthToken = auth.Token;
         return(auth.Token);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
        private void Step2Button_Click(object sender, EventArgs e)
        {
            Flickr flickr = new Flickr(ApiKey.Text, SharedSecret.Text);

            try
            {
                Auth auth = flickr.AuthGetToken(Frob);
                OutputTextbox.Text += "User Authenticated = " + auth.User.UserName + "\r\n";
                OutputTextbox.Text += "Auth Token = " + auth.Token + "\r\n";

                AuthToken.Text = auth.Token;
            }
            catch (FlickrException ex)
            {
                OutputTextbox.Text += "Authentication failed : " + ex.Message + "\r\n";
            }

            Step1Button.Enabled = true;
            Step2Button.Enabled = false;
            Step3Button.Enabled = false;
        }
Exemplo n.º 7
0
 public static void CompleteAuthentication()
 {
     Flickr flickr = new Flickr(ApiKey, SharedSecret);
     try
     {
         Auth auth = flickr.AuthGetToken(frob);
         authStatus = "SUCCESS";
         authenticatedUsername = auth.User.Username;
         authToken = auth.Token;
         successMessage = "Authentication Successful!";
     }
     catch (FlickrException ex)
     {
         authStatus = "FAILED";
         authenticatedUsername = "";
         authToken = "";
         if (ex.Message == "Invalid frob (108)")
             errorMessage = ex.Message + " Did you give the app permission?";
         else
             errorMessage = ex.Message;
     }
 }
        void ButtonOKClick(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(flickrFrob))
            {
                Flickr flickr = new Flickr(FlickrUtils.Flickr_API_KEY, FlickrUtils.Flickr_SHARED_SECRET);

                try
                {
                    Auth auth = flickr.AuthGetToken(flickrFrob);

                    textBoxAuthToken.Text = auth.Token;
                    this.DialogResult = DialogResult.OK;
                }
                catch (FlickrException ex)
                {
                    MessageBox.Show("Authentication failed : " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                this.DialogResult = DialogResult.OK;
            }
        }
        private void buttonAuthenticate_Click(object sender, EventArgs e)
        {
            Flickr flickr = new Flickr(FlickrUtils.Flickr_API_KEY, FlickrUtils.Flickr_SHARED_SECRET);

            if (string.IsNullOrEmpty(flickrFrob))
            {
                flickrFrob = flickr.AuthGetFrob();
                string url = flickr.AuthCalcUrl(flickrFrob, AuthLevel.Write);
                System.Diagnostics.Process.Start(url);
            }
            else
            {
                flickrFrob = string.Empty;
                Auth auth = flickr.AuthGetToken(flickrFrob);
                textBoxAuthToken.Text = auth.Token;
            }
        }
Exemplo n.º 10
0
        private string FlickrGetToken()
        {
            try
            {
                Flickr f = new Flickr(Properties.Settings.Default.FlickrApiKey, Properties.Settings.Default.FlickrShared);
                f.Proxy = GetProxy(true);

                string Frob = f.AuthGetFrob();
                string url = f.AuthCalcUrl(Frob, AuthLevel.Read | AuthLevel.Write | AuthLevel.Delete);
                System.Diagnostics.Process.Start(url);

                if (messages_level==MessagesLevel.MessagesNone || MessageBox.Show("Please confirm that you've authorized FlickrSync to access your flickr account", "Confirmation", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    Auth auth = f.AuthGetToken(Frob);
                    Properties.Settings.Default.FlickrToken = auth.Token;
                    SaveConfig();
                    return Properties.Settings.Default.FlickrToken;
                }
            }
            catch (Exception e)
            {
                if (Properties.Settings.Default.FlickrToken == "")
                    Error("Unable to obtain Flickr Token", e, ErrorType.Connect);
                else
                    Error("Error obtaining Flickr Token", e, ErrorType.Normal);
            }

            return "";
        }
Exemplo n.º 11
0
 public static void Main(string[] args)
 {
     Console.WriteLine("ThumbSync - Flickr Sync by Tristan Phillips   v0.4");
     if (!ParseArgs(args))
     {
         Console.WriteLine("usage: ThumbSync.exe -u <userIDs , seperated> -o <out directory>\n" +
                           "Optionals:\n" +
                           "-c <count, default 20> \n" +
                           "-s get small photos (default medium) \n" +
                           "-t get thumbnails (default medium) \n" +
                           "-l get large photos (default medium) \n" +
                           "-T <pre authenticated token> \n" +
                           "-O overwrite existing local copy \n" +
                           "-p <start at page> \n" +
                           "-th <throttle millisecs> \n" +
                           "-W use white average file validation");
         return;
     }
     string[]         userIDs = userIds.Split(',');
     FlickrNet.Flickr f       = new FlickrNet.Flickr("5f9dbe6d11086346eacc6d9b9d81a5f5", "826ddba13f621f18");
     if (token == "")
     {
         string frob = f.AuthGetFrob();
         string url  = f.AuthCalcUrl(frob, AuthLevel.Read);
         Console.WriteLine("Go here & authenticate: " + url);
         Console.WriteLine("When you are done, press return . . .  I'll be waiting . . .");
         try
         {
             /*
              * System.Diagnostics.Process p = new System.Diagnostics.Process();
              * p.StartInfo.FileName="c:\\program files\\internet explorer\\iExplore.exe";
              * p.StartInfo.Arguments = url;
              * p.Start();
              * System.Diagnostics.Process p2 = new System.Diagnostics.Process();
              * p2.StartInfo.FileName="/Applications/Safari.app/Contents/MacOS/Safari";
              * p2.StartInfo.Arguments = "\"" + url + "\"";
              * p2.Start();
              */
         }
         catch {}
         Console.ReadLine();
         FlickrNet.Auth auth = f.AuthGetToken(frob);
         Console.WriteLine("Token (you can re-use this with -T): " + auth.Token);
         token = auth.Token;
     }
     f.AuthToken = token;
     foreach (string userId in userIDs)
     {
         Person per        = f.PeopleGetInfo(userId);
         string personName = per.UserName;
         Console.WriteLine("Processing " + maxPerPerson + " from " + per.UserName + "(" + per.RealName + ")");
         while (collected < maxPerPerson)
         {
             PhotoCollection res = f.PeopleGetPhotos(userId, page, pageSize);
             collected += res.Count;
             if (res.Page == res.Pages)
             {
                 collected = maxPerPerson;
             }
             foreach (Photo p in res)
             {
                 bool processed     = false;
                 int  tries         = 0;
                 int  startSecsWait = 120;
                 int  maxTries      = 15;
                 while (!processed && tries < maxTries)
                 {
                     try
                     {
                         tries++;
                         Console.Write(". ");
                         if (x % 10 == 0)
                         {
                             Console.Write(x + " ");
                         }
                         PhotoInfo info = f.PhotosGetInfo(p.PhotoId);
                         string    tag  = info.Tags.Count > 0 ? info.Tags[0].Raw : "NotTagged";
                         if (!System.IO.Directory.Exists(OutDir + System.IO.Path.DirectorySeparatorChar + personName + "-" + tag))
                         {
                             System.IO.Directory.CreateDirectory(OutDir + System.IO.Path.DirectorySeparatorChar + personName + "-" + tag);
                         }
                         string url = smallPhotos ? p.SmallUrl : p.MediumUrl;
                         url = largeSize ? p.LargeUrl : url;
                         url = thumbnailSize ? p.ThumbnailUrl: url;
                         string[] pNames   = url.Split('/');
                         string   pName    = pNames[pNames.Length - 1];
                         string   fileName = OutDir + System.IO.Path.DirectorySeparatorChar + personName + "-" + tag + System.IO.Path.DirectorySeparatorChar + pName;
                         if (!System.IO.File.Exists(fileName) || overwrite)
                         {
                             new System.Net.WebClient().DownloadFile(url, fileName);
                             if (checkForWhiteFiles)
                             {
                                 WhiteCheck(fileName);
                             }
                         }
                         processed = true;
                         x++;
                     }
                     catch (Exception e)
                     {
                         int wait = startSecsWait * tries;
                         Console.WriteLine(String.Format("There was a problem processing page {0} (x={1}, page={2}, pageSize={3}, collected={4})", page, x, page, pageSize, collected));
                         Console.WriteLine(e.Message);
                         if (tries < maxTries)
                         {
                             Console.WriteLine("Will retry in " + wait / 60 + " mins . . .");
                         }
                         System.Threading.Thread.Sleep(wait * 1000);
                     }
                 }
                 if (throttle > 0)
                 {
                     System.Threading.Thread.Sleep(throttle);
                 }
             }
             page++;
         }
     }
     Console.WriteLine("Done");
 }
Exemplo n.º 12
0
 private void CompleteAuthButton_Click(object sender, EventArgs e)
 {
     // Create Flickr instance
     Flickr flickr = new Flickr(Program.FlickrAPIKey, Program.FlickrSharedSecretKey);
     try {
         // use the temporary Frob to get the authentication
         Auth auth = flickr.AuthGetToken(tempFrob);
         // Store this Token for later usage,
         // or set your Flickr instance to use it.
         System.Windows.Forms.MessageBox.Show("User authenticated successfully");
         Terminals.Logging.Log.Info("User authenticated successfully. Authentication token is " + auth.Token + ".User id is " + auth.User.UserId + ", username is" + auth.User.Username);
         flickr.AuthToken = auth.Token;
         Settings.FlickrToken = auth.Token;
     } catch(FlickrException ex) {
         // If user did not authenticat your application
         // then a FlickrException will be thrown.
         Terminals.Logging.Log.Info("User not authenticated successfully", ex);
         System.Windows.Forms.MessageBox.Show("User did not authenticate you" +ex.Message);
     }
 }