Inheritance: IFlickrParsable
Ejemplo 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;
                }
            }
        }
Ejemplo n.º 2
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)
             {
             }
         }
     }
 }
Ejemplo n.º 3
0
 private void Logout()
 {
     token = null;
     auth = null;
     fr = new FlickrRemote (token, current_service);
     Preferences.Set (current_service.PreferencePath, String.Empty);
     CurrentState = State.Disconnected;
 }
Ejemplo n.º 4
0
        public void CheckAuthorization()
        {
            AuthorizationEventArgs args = new AuthorizationEventArgs ();

            try {
                args.Auth = fr.CheckLogin ();
            } catch (FlickrException e) {
                args.Exception = e;
            }

            Gtk.Application.Invoke (this, args, delegate (object sender, EventArgs sargs) {
                AuthorizationEventArgs wargs = (AuthorizationEventArgs) sargs;

                do_export_flickr.Sensitive = wargs.Auth != null;
                if (wargs.Auth != null) {
                    token = wargs.Auth.Token;
                    auth = wargs.Auth;
                    CurrentState = State.Authorized;
                    Preferences.Set (current_service.PreferencePath, token);
                } else {
                    CurrentState = State.Disconnected;
                }
            });
        }
Ejemplo n.º 5
0
        public Auth CheckLogin()
        {
            try {
            if (frob == null) {
                frob = flickr.AuthGetFrob ();
                if (frob ==  null) {
                    Log.Error ("ERROR: Problems login in Flickr. Don't have a frob");
                    return null;
                }
            }
            } catch (Exception e) {
            Log.Error ("Error logging in: {0}", e.Message);
            }

            if (token == null) {
            try {
                auth = flickr.AuthGetToken(frob);
                token = auth.Token;
                flickr.AuthToken = token;

                return auth;
            } catch (FlickrNet.FlickrApiException ex) {
                Log.Error ("Problems logging in to Flickr - " + ex.OriginalMessage);
                return null;
            }
            }

            auth = flickr.AuthCheckToken ("token");
            return auth;
        }
        public void CheckAuthorization()
        {
            AuthorizationEventArgs args = new AuthorizationEventArgs ();

            try {
                args.Auth = fr.CheckLogin ();
            } catch (FlickrException e) {
                args.Exception = e;
            } catch (Exception e) {
                HigMessageDialog md =
                    new HigMessageDialog (Dialog,
                                  Gtk.DialogFlags.Modal |
                                  Gtk.DialogFlags.DestroyWithParent,
                                  Gtk.MessageType.Error, Gtk.ButtonsType.Ok,
                                  Catalog.GetString ("Unable to log on"), e.Message);

                md.Run ();
                md.Destroy ();
                return;
            }

            ThreadAssist.ProxyToMain (() => {
                do_export_flickr.Sensitive = args.Auth != null;
                if (args.Auth != null) {
                    token = args.Auth.Token;
                    auth = args.Auth;
                    CurrentState = State.Authorized;
                    Preferences.Set (current_service.PreferencePath, token);
                } else {
                    CurrentState = State.Disconnected;
                }
            });
        }
Ejemplo n.º 7
0
        /// <summary>
        /// After the user has authenticated your application on the flickr web site call this 
        /// method with the FROB (either stored from <see cref="AuthGetFrob"/> or returned in the URL
        /// from the Flickr web site) to get the users token.
        /// </summary>
        /// <param name="frob">The string containing the FROB.</param>
        /// <returns>A <see cref="Auth"/> object containing user and token details.</returns>
        public Auth AuthGetToken(string frob)
        {
            if( _sharedSecret == null ) throw new FlickrException(0, "AuthGetToken requires signing. Please supply api key and secret.");

            Hashtable parameters = new Hashtable();
            parameters.Add("method", "flickr.auth.getToken");
            parameters.Add("frob", frob);

            FlickrNet.Response response = GetResponseNoCache(parameters);
            if( response.Status == ResponseStatus.OK )
            {
                Auth auth = new Auth(response.AllElements[0]);
                return auth;
            }
            else
            {
                throw new FlickrException(response.Error);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets the full token details for a given mini token, entered by the user following a 
        /// web based authentication.
        /// </summary>
        /// <param name="miniToken">The mini token.</param>
        /// <returns>An instance <see cref="Auth"/> class, detailing the user and their full token.</returns>
        public Auth AuthGetFullToken(string miniToken)
        {
            Hashtable parameters = new Hashtable();
            parameters.Add("method", "flickr.auth.getFullToken");
            parameters.Add("mini_token", miniToken.Replace("-", ""));
            FlickrNet.Response response = GetResponseNoCache(parameters);

            if( response.Status == ResponseStatus.OK )
            {
                Auth auth = new Auth(response.AllElements[0]);
                return auth;
            }
            else
            {
                throw new FlickrException(response.Error);
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Checks a authentication token with the flickr service to make
        /// sure it is still valid.
        /// </summary>
        /// <param name="token">The authentication token to check.</param>
        /// <returns>The <see cref="Auth"/> object detailing the user for the token.</returns>
        public Auth AuthCheckToken(string token)
        {
            Hashtable parameters = new Hashtable();
            parameters.Add("method", "flickr.auth.checkToken");
            parameters.Add("auth_token", token);

            FlickrNet.Response response = GetResponseNoCache(parameters);
            if( response.Status == ResponseStatus.OK )
            {
                Auth auth = new Auth(response.AllElements[0]);
                return auth;
            }
            else
            {
                throw new FlickrException(response.Error);
            }
        }
Ejemplo n.º 10
0
        public void AuthClassBasicTest()
        {
            string authResponse = "<auth><token>TheToken</token><perms>delete</perms><user nsid=\"41888973@N00\" username=\"Sam Judson\" fullname=\"Sam Judson\" /></auth>";

            XmlTextReader reader = new XmlTextReader(new StringReader(authResponse));
            reader.Read();

            Auth auth = new Auth();
            IFlickrParsable parsable = auth as IFlickrParsable;

            parsable.Load(reader);

            Assert.AreEqual("TheToken", auth.Token);
            Assert.AreEqual(AuthLevel.Delete, auth.Permissions);
            Assert.AreEqual("41888973@N00", auth.User.UserId);
            Assert.AreEqual("Sam Judson", auth.User.UserName);
            Assert.AreEqual("Sam Judson", auth.User.FullName);
        }
Ejemplo n.º 11
0
        private void btnValidation_Click(object sender, RoutedEventArgs e)
        {
            // Récupère l'autentification
            try
            {
                autFlickr = conFlickr.AuthGetToken(tempFrob);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Une erreur vient de ce produire :" + Environment.NewLine + ex.Message,
                    "Erreur d'authentification à Flickr", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            // Active le bouton "Suivant"
            btnSuivant.IsEnabled = true;

            // Affiche le quota restant
            if (conFlickr.PeopleGetUploadStatus().IsPro == false)
            {
                lblQuota.Content = String.Format("Quota restant sur votre compte Flickr : {0} Kio",
                    conFlickr.PeopleGetUploadStatus().BandwidthRemainingKB);
            }
            else
            {
                lblQuota.Content = "Quota restant sur votre compte Flickr : ∞ Kio";
            }

            // Affiche un message de bienvenue
            MessageBox.Show("Bienvenue " + conFlickr.PeopleGetUploadStatus().UserName + " !", "Bienvenue",
                MessageBoxButton.OK, MessageBoxImage.Information);

            // Récupère la liste des albums
            cmbAlbum.Items.Clear();
            listeAlbums.Clear();
            cmbAlbum.Items.Add("Sélectionnez un album");
            listeAlbums.Add("-1");
            cmbAlbum.Items.Add("Ajoutez un nouvel album…");
            listeAlbums.Add("0");
            PhotosetCollection lstAlbums = conFlickr.PhotosetsGetList();
            foreach (Photoset album in lstAlbums)
            {
                cmbAlbum.Items.Add(album.Title);
                listeAlbums.Add(album.PhotosetId);
            }
            cmbAlbum.SelectedIndex = 0;
        }
Ejemplo n.º 12
0
		/// <summary>
		/// After the user has authenticated your application on the flickr web site call this
		/// method with the FROB (either stored from <see cref="AuthGetFrob"/> or returned in the URL
		/// from the Flickr web site) to get the users token.
		/// </summary>
		/// <param name="frob">The string containing the FROB.</param>
		/// <returns>A <see cref="Auth"/> object containing user and token details.</returns>
		public Auth AuthGetToken(string frob)
		{
			if( _sharedSecret == null ) throw new SignatureRequiredException();

			Hashtable parameters = new Hashtable();
			parameters.Add("method", "flickr.auth.getToken");
			parameters.Add("frob", frob);

			FlickrNet.Response response = GetResponseNoCache(parameters);
			if( response.Status == ResponseStatus.OK )
			{
				Auth auth = new Auth(response.AllElements[CurrentService==SupportedService.Zooomr?1:0]);
				return auth;
			}
			else
			{
				throw new FlickrApiException(response.Error);
			}
		}
Ejemplo n.º 13
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");
 }
Ejemplo n.º 14
0
        public override System.Windows.Forms.DialogResult CreateContent(System.Windows.Forms.IWin32Window dialogOwner, ref string newContent)
        {
            DialogResult       result;
            DoWorkEventHandler handler = null;

            FlickrNet.Auth validAuthToken = null;
            FlickrContext  context        = new FlickrContext(base.Options);

            token = context.FlickrAuthToken;

            // we have a token saved already and
            // need to verify it with Flickr
            if (!string.IsNullOrEmpty(token))
            {
                using (VerifyAuth vauth = new VerifyAuth())
                {
                    if (handler == null)
                    {
                        handler = delegate(object sender, DoWorkEventArgs args)
                        {
                            FlickrNet.Flickr fp = FlickrPluginHelper.GetFlickrProxy();
                            validAuthToken = fp.AuthCheckToken(token);
                            if (validAuthToken != null)
                            {
                                token = validAuthToken.Token;
                            }
                        };
                    }
                    vauth.DoWork += handler;
                    result        = vauth.ShowDialog(dialogOwner);
                    if (result != DialogResult.OK)
                    {
                        return(result);
                    }
                }
            }

            /* we didn't get a valid auth token
             * it might have expired or is just invalid/revoked
             * prompt the user to re-auth
             * OR
             * we don't have a saved token and know
             * we need to get one first so show the auth process
             */
            if (string.IsNullOrEmpty(token) || (validAuthToken == null))
            {
                token = AuthManager.Authenticate(dialogOwner, context);
            }

            if (string.IsNullOrEmpty(token))
            {
                return(DialogResult.Cancel);
            }

            using (InsertFlickrImageForm flickr = new InsertFlickrImageForm(new FlickrContext(base.Options)))
            {
                System.Windows.Forms.DialogResult formResult = flickr.ShowDialog(dialogOwner);

                context.FlickrUserId     = flickr.FlickrUserId.Trim();
                context.FlickrUserName   = flickr.FlickrUserName.Trim();
                context.FlickrAuthUserId = flickr.FlickrAuthUserId.Trim();

                if (formResult == System.Windows.Forms.DialogResult.OK)
                {
                    ImageSize imgsize = flickr.SelectedImageSize;

                    foreach (FlickrNet.Photo photo in flickr.SelectedPhotos)
                    {
                        newContent += FlickrPluginHelper.GenerateFlickrHtml(photo, GetImageUrl(photo, imgsize), flickr.CssClass, flickr.BorderThickness, flickr.VerticalPadding, flickr.HorizontalPadding, flickr.Alignment, flickr.EnableHyperLink, flickr.FlickrUserId);
                    }
                }
                return(formResult);
            }
        }