Help with setting delete permission from app / missing Photoset URL

Topics: Developer Forum
Oct 13, 2007 at 3:08 AM
I am having problems allowing the user to delete one of their own photos from Flickr. If I try it the app stops at PhotosDelete in Flickr.cs with this exception: "Insufficient permissions. Method requires delete privileges; write granted. (99))". From reading the API I know somewhere I am meant to set the permissions to "delete" when I authenticate but am confused about how to do this.

This is how I set my Flickr object up when the app starts up:

dim f as Flickr
f = New Flickr(FlickrAPIkey, FlickrAPISecretKey, FlickrAuthToken)

Everything except for Delete works fine so how do I set the delete permission to enable this functionality to work? I can't see a property on the Flickr object - am I blind, stupid or both? (You don't have to answer that BTW!)

I am also finding that PhotoSet objects do not have the URL property populated - I am wanting to allow the user to select one of their own Photosets (from a TreeView control I populate) and then view the actual flickr Photoset in a WebBrowser control but the URL is always null... any idea why?

Mike
Coordinator
Oct 15, 2007 at 10:08 AM
1) Delete permissions

For PhotosDelete to work the user must have given you Delete permission.
When calculating the authentication url you are required to enter the AuthLevel, which should be passed as AuthLevel.Delete. Once the token has been obtained for that user it can then be reused as you have illustrated.

2) Photoset Url

Flickr doesn't seem to be returing the URL anymore (I'm assuming it was at some point, but I honestly can't remember).

I'll change the code so it calculates the URL, but in the mean time you can work it out yourself, by using the following URL format:

http://www.flickr.com/photos/{user-id}/sets/{photoset-id}
Oct 15, 2007 at 2:20 PM
Thanks Sam... I'm still a tad confused though as these are only ever my own photos I am wanting to delete so I thought as long as I was passing the two keys in (API and secret) it would work.... do you have any examples as I just can't seem to get my brain to work this one out! (I guess I also need to do some more careful reading of the API pages.)

As regards the photoset URLs, I have switched to calculating them myself (as you suggested) but it certainly might be a good thing to add in since Yahoo seemingly don't provide it any more.

One other thing - if I wanted to get a list of random photos from my own collections/sets (say to show as a mosiac of thumbnails on a non-flickr website) how could I do that?
The nearest I can see would be calling something like GetRecent and then using random photos from that list but that seems to get recent photos from everyone's photos... what I want to do is to get a random sampling of say 20 or 30 photos just from my own collection. I've looked and looked but can't see any way in the existing API to do this - what would you suggest?

Thanks for the help... it's amazing how easy FlickrNet makes interacting with Flickr.
Coordinator
Oct 15, 2007 at 3:57 PM
There is an example of doing authentication in the example application page Examples.

There is no specific 'random' function available from Flickr. You can either use PhotosSearch or PhotosetsGetPhotos to get your own photos or a particular sets photos. Then just pick random photos from the resulting array.
Oct 15, 2007 at 9:45 PM
Thanks Sam.
Oct 17, 2007 at 1:51 AM
Edited Oct 17, 2007 at 6:05 AM
Just in case you're interested (or anyone else is trying to pick random images from their own sets) what I ended up doing (as you suggested) was a search of my own photos - specifying no search keywords returned all my photos which is what i wanted. I then used the following code to pick 20 random images ensuring there were no repeats - would this be something you would consider adding to a future release of FlickrNet? The method could be passed the number of photos to pick, the UserID and optionally search tags (defaulting to string.empty) and return an array or collection of Photo objects maybe. Anyway, it's just a thought - not sure if you only tend to wrap functions that already exist in the Flickr API or whether you are happy to add custom functionality such as this. (Either way you probably have better things to do!!)


Dim phset As Photos = f.PhotosSearch(FlickrUserID, "")

If phset.PhotoCollection.GetLength(0) > 0 Then

Dim intPhotosToFetch as Integer = 20
Dim intNdx As Integer = 0
Dim intRnd As Integer = 0
Dim intCnt As Integer = phset.PhotoCollection.GetUpperBound(0)
Dim tnPhotos() As Photo
Dim ph As Photo
Dim hashNumbers As New Hashtable

For i As Integer = 0 To intPhotosToFetch - 1

Randomize()
intRnd = CInt(Int((intCnt * Rnd()) + 1))

'If the random number has already been selected then generate new ones until a unique one is found.
Do Until hashNumbers.Item(intRnd) = Nothing
Randomize()
intRnd = CInt(Int((intCnt * Rnd()) + 1))
Loop
hashNumbers.Add(intRnd, intRnd)

'Now add our randomly selected photo to the array.
ph = phset.PhotoCollection(intRnd)
ReDim Preserve tnPhotos(intNdx)
tnPhotos(intNdx) = ph
intNdx += 1

Next