PhotosSearch returning deleted photos?

Topics: Developer Forum, User Forum
Dec 16, 2009 at 1:52 PM
Edited Dec 16, 2009 at 1:53 PM

Hi,

I have been trying to code something rather simple, using the guide written on coding4fun and the other examples, i am trying to download and delete photos from my Flickr account. I manage to authenticate, download private photos and then delete them, however, when i run the code again, it retreives information about the last photo i had on my account even though its deleted and my photostream is empty. Is there a cache that i need to clear? Is there a way to ignore photos that... don't really exist and not retrieve them with PhotoSearch? 

 

 

public static void findPhoto(Flickr iFlickr, string Id)
        {
          
            List<Photo> allPhotos = null;
            
            PhotoSearchOptions userSearch = new PhotoSearchOptions();
            userSearch.UserId = Id;
            userSearch.SortOrder = PhotoSearchSortOrder.None;
            userSearch.PrivacyFilter = PrivacyFilter.CompletelyPrivate;
            allPhotos = iFlickr.PhotosSearch(userSearch);

                foreach (Photo photo in allPhotos)
                {
                        Client.DownloadFile(photo.LargeUrl, @"d:\photos\" + photo.PhotoId + ".jpg");
                        iFlickr.PhotosDelete(photo.PhotoId);       
                }
    
              
       }
Anyone has any idea what i'm doing wrong?
Thanks.

 

 

 

 

public static void findPhoto(Flickr iFlickr, string Id)
        {
            WebClient Client = new WebClient ();
            iSQL mySQL = new iSQL();
           // mySQL.iConnect();
            List<Photo> allPhotos = null;
           // Photos usersPhotos = null;
            //PhotoCollection allPhotos;
            
            
           
            //Console.WriteLine(Id);
            PhotoSearchOptions userSearch = new PhotoSearchOptions();
            userSearch.UserId = Id;
            //userSearch.SortOrder = PhotoSearchSortOrder.DatePostedAsc;
            
            while (1 == 1)
            {
                Console.WriteLine("loop");
                Console.ReadKey();
                //usersPhotos.Clear();
                //allPhotos.Clear();
                //usersPhotos = iFlickr.PhotosSearch(userSearch);
                userSearch.SortOrder = PhotoSearchSortOrder.None;
                userSearch.PrivacyFilter = PrivacyFilter.CompletelyPrivate;
                allPhotos = iFlickr.PhotosSearch(userSearch);
                PhotoSearchOptions options = new PhotoSearchOptions();
                options.UserId = "45348784@N05";
                Photos photos = iFlickr.PhotosSearch(options);
                
                //allPhotos.Clear();
                Console.WriteLine("number of photos : " + allPhotos.Count);
                if (allPhotos.Count > 0)
                {
                foreach (Photo photo in photos)
                {
                        Console.WriteLine("Photos date is " + photo.DateTaken);
                        Console.Write("Photos title is " + photo.Title);
                        //Console.ReadKey();
                        Client.DownloadFile(photo.LargeUrl, @"C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\WebSites\PhotoShareSite\images\" + photo.PhotoId + ".jpg");
                        mySQL.iConnect();
                        mySQL.insertPhoto(photo.Title, @"images/" + photo.PhotoId + ".jpg", DateTime.Now);
                        mySQL.iDisconnect();
                        iFlickr.PhotosDelete(photo.PhotoId);
                        
                    }
    
                }
              // usersPhotos.Clear();
               allPhotos.Clear();
               Console.WriteLine("number of photos after clear : " + allPhotos.Count);
                //mySQL.iDisconnect();
            }

 

 

Dec 16, 2009 at 8:12 PM

I was having the same issue and I found if I added "flickr.CacheDisabled = True" just before I called the photosearch I was ok.

 

My code looks like this

        Dim flickr As New FlickrNet.Flickr()
        Dim options As New FlickrNet.PhotoSearchOptions()
        flickr.CacheDisabled = True

        options.UserId = ConfigurationManager.AppSettings.Get("UserId")
        options.PerPage = 20
        options.SortOrder = FlickrNet.PhotoSearchSortOrder.DatePostedDesc

        Dim photos As FlickrNet.Photos = flickr.PhotosSearch(options)

        If photos.PhotoCollection Is Nothing Then
            Return New FlickrNet.PhotoCollection()
        Else
            Return photos.PhotoCollection
        End If

Give it a shot

Coordinator
Dec 17, 2009 at 8:18 AM

Yes, there is a Cache built in to the Flickr API.

You have two choices, either disable the cache completely, or use the Flush method to clear the cache (either all the cache, or for a specific url).

If you Flush the cache you can use the LastRequest property to get the most recent URL to Flush.

 

public static void findPhoto(Flickr iFlickr, string Id)
{

List<Photo> allPhotos = null;

PhotoSearchOptions userSearch = new PhotoSearchOptions();
userSearch.UserId = Id;
userSearch.SortOrder = PhotoSearchSortOrder.None;
userSearch.PrivacyFilter = PrivacyFilter.CompletelyPrivate;
allPhotos = iFlickr.PhotosSearch(userSearch);
Flickr.Flush(iFlickr.LastRequest);

foreach (Photo photo in allPhotos)
{
Client.DownloadFile(photo.LargeUrl, @"d:\photos\" + photo.PhotoId + ".jpg");
iFlickr.PhotosDelete(photo.PhotoId);
}


}