UserPreferences

FlickrSystem/ApiExample/ChangingPermissions


I wrote a Python script to change the privacy settings of a photoset of images. I tend to set my photos to visible to only myself or to my friends and family before then making them publicly available. The Flickr user interface allows changes to images one at a time, which works ok for small sets of images. But I have been creating sets with dozens of photos, making privacy shifts extremely tedious. While I await the [WWW]addition of batch operations to the flickr interface, I decided to do some programming with the [WWW]Flickr API Services.

If you want to play with the flickr API, you will need to [WWW]request a key. There are both SOAP and REST interfaces to Flickr.

Also, there are two Python libraries that use these interfaces. ([WWW]FlickrClient - micampe.it and [WWW]flickr.py (James Clarke). There seems to be a basic tradeoff between the two modules: completeness of the first vs convenience of the latter. I quickly decided on the first library because the lightweight wrapper gave access to the entire API.

I will post here my little script. (It's not the most elegant solution -- but shows how one can use [WWW]FlickrClient - micampe.it

  1 
  2 
  3 
  4 
  5 
  6 
  7 
  8 
  9 
 10 
 11 
 12 
 13 
 14 
 15 
 16 
 17 
 18 
 19 
 20 
 21 
 22 
 23 
 24 
 25 
 26 
 27 
 28 
 29 
 30 
 31 
 32 
 33 

API_KEY = 'INSERT YOUR API KEY HERE'
USER_EMAIL = "INSERT EMAIL HERE"
USER_PASSWORD = "INSERT PASSWORD HERE"
USER_ID = "INSERT FLICKR ID HERE"

def makeSetPublic(photoSetID,flAll):
# general intention is to change the pictures in the photoset public.
#if flAll is false, then leave as private those that aren't for view by family and friends.

    photoset = client.flickr_photosets_getPhotos(photoset_id=photoSetID, email=USER_EMAIL, password=USER_PASSWORD)
    for photo in photoset:
        photo_id = photo('id')
        photo_secret = photo('secret')
        photoInfo = getPhotoInfo(photo_id)
        is_public = photoInfo.visibility("ispublic")
        is_friend = photoInfo.visibility("isfriend")
        is_family = photoInfo.visibility("isfamily")
        perm_comment = photoInfo.permissions("permcomment")
        perm_addmeta = photoInfo.permissions("permaddmeta")
        print "id:%s  title:%s  public:%s  friend:%s  family:%s" % (photo_id, str(photoInfo.title), is_public, is_friend, is_friend)

# change the permissions to public unless we want to keep those not already for family and friends as private

        if flAll:
            setPhotoPerm(photo_id,is_public=1,is_friend=1, is_family=1, perm_comment=perm_comment, perm_addmeta=perm_addmeta)
        else:
            if is_friend == '1' and is_family == '1':
                setPhotoPerm(photo_id,is_public=1,is_friend=1, is_family=1, perm_comment=perm_comment, perm_addmeta=perm_addmeta)


def setPhotoPerm(photoID,is_public,is_friend,is_family,perm_comment,perm_addmeta):
    client.flickr_photos_setPerms(email=USER_EMAIL, password=USER_PASSWORD, photo_id=photoID, is_public=is_public, is_friend=is_friend, is_family=is_family, perm_comment=perm_comment, perm_addmeta =perm_addmeta)