I'm a little confused about Flickr API keys. Would I be correct in thinking that an API key is tied to a single Flickr account?
What I'd like to do is create a tool that lets my site's users upload photos to their own Flickr accounts. At first I thought that all I needed was to specify a single API key and then authenticate the user before uploading, but now I'm starting to think that
each user must specify their own API key. Basically, I'm lost.
Ideally, I would specify my API key in my web.config once and my users would simply enter their Flickr user name and password before uploading their photos.
Can someone get me back on track please?
OK, I think I have figured it out. Can someone confirm that the following is the correct way of doing things?
1. I created a page with the following code (VB.Net):
Dim f As Flickr = New Flickr("myAPIKey", "mySecret")
Dim url As String = f.AuthCalcWebUrl(AuthLevel.Write)
2. This redirects the user to Flickr where they are asked to sign in and then asked if they want to allow my site to work with their Flickr account.
3. The user is then sent back to the Callback URL (specified in Flickr for the specific API key).
4. The callback page now gets the user to specify a file to upload (using ASP.NET fileupload control), enter a photo title, tags and description.
5. The user clicks the "upload" button and the following code is executed:
Dim FlickrAuth As Flickr = New Flickr("myAPIKey", "mySecret")
Dim a As Auth = FlickrAuth.AuthGetToken(Request.QueryString("frob"))
Dim strTitle As String = txtTitle.Text
Dim strDescription As String = txtDescription.Text
Dim strTags As String = txtTags.Text
Dim strfile As String = fileUpload.FileName
Dim FlickrUpload As Flickr = New Flickr("myAPIKey", "mySecret", a.Token)
Dim strPhotoID As String = FlickrUpload.UploadPicture(Server.MapPath(fileUpload.FileName), strTitle, strDescription)
Catch ex As Exception
This worked for me! I would really appreciate your comments - especially if I can do things in a better / more efficient way.
Many thanks again,
Dec 1, 2006 at 9:19 AM
Looks fine to me, although you could sotre the AuthToken so the user doesn't have to authenticate the next time they want to use your web site (cookie maybe?)
There is a sample web application on the Examples page that covers authentication (although not upload).
Also note that providing this facility via a web site is terrible for your bandwidth, and response times. This is because the user has to upload the file to your web site, and then your web site uploads the file to Flickr, so the bandwidth is twice and the
page takes twice as long to run.