views:

178

answers:

1

I have a web application that I want to sync with Flickr. I don't want the users to have to log into Flickr so I plan to use a single login. I believe I'll need to do something like this:

import flickrapi
flickr = flickrapi.FlickrAPI(myKey, mySecret)
(token, frob) = flickr.get_token_part_one(perms='write', my_auth_callback)
flickr.get_token_part_two((token, frob,))
flickr.what_have_you(...

I don't know what my_auth_callback should look like though. I suspect it will have to post my login information to flickr. Could I do the get_token_part_one step just once manually perhaps and then re-use it in get_token_part_two?

Edit

Wooble has it. Here are some explicit directions that I wrote down using the Django shell and the flickrapi library.

import flickrapi
api_key = "xxxx...xxxx"
api_secret = "xxxx...xxxx"
_flickr = flickrapi.FlickrAPI(api_key, api_secret)
_flickr.web_login_url("write")
# Go to that url.
# That sends you back to the callback url you set by "editing the
# authentication workflow" on your flicks admin page located on the site.
# This callback url will contain a frob in the form
# xxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx-xxxxxxxx
_flickr.get_token("xxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxx-xxxxxxxx")
# That returns the token. Then test with

import flickrapi
from django.conf import settings
_flickr = flickrapi.FlickrAPI(api_key, api_secret, token=api_token)
_flickr.groups_pools_getGroups()
+1  A: 

If you don't want your users to authenticate with Flickr, you don't need to use the token-getting code at all. Just get a token for yourself once and include it with your code.

Note that "syncing" other users' photos with your own account probably breaks Flickr's TOS.

Wooble
I've been unable to "Just get a token for yourself once" though I've tried for a while using a variety of approaches both manual and in Python. Anybody have any practical advice or code?
Dave Aaron Smith
I get a lot of "Error: 108: Invalid frob"
Dave Aaron Smith
Have you read flickr's auth documentation? You should just need to call flickr.auth.getFrob, visit the correct page at Flickr to authorize it, then call flickr.auth.getToken using the frob you got with the first call. The token that's returned can be embedded in your application as a string if you really want to allow your users to authenticate as you.
Wooble