Thursday, November 15, 2007

playing with Python FlickrAPI

Finally relaxing again, after fixing the server. And at the same time, got my self a couple of pictures i taken by my friends. So i decide to play with stuff that i always wanted to do for sometime, playing around with the python FlickrAPI

Since i'm lazy, and i got some pictures, that i don't want to upload manually, so i decide to automate it. There is a few tools for doing this, from ruby, curl, python. Flickr actually provide a list of language binding for their api. I decide to play around with a python api.

Before i can do that, i need the api key, which can found on flickr api site. Just click on Your Api Key. after going through a few steps, the key is there. There should be a api key and a secret key, you will need the api key to use the application, to authenticate on your flickr account you will need the secret key.

Then get the api here, extract it somewhere, then run
python setup.py install

in the same directory. It is in the readme.

Then though the tutorial online.
import flickrapi
#this is the set the key
api_key='your api key'
secret_key='your secret key
flickr=flickrapi.FlickrAPI(api_key,secret_key)
#authenticate
(token,trob)=flickr.getTokenPartOne(perms='write')
if not token:raw_input("Press Enter After You Authorize This Program")
flickr.getTokenPartTwo((token,trob))
#the call back function
def func(progress,done):
if done:
print "done"
else:
print "at %s%%" % progress
#the upload function, change the filename, and tag, or if want it to be private, change is_public=1 to is_public=0
flickr.upload(filename="your image path",callback=func,is_public=1,tags='your tag')

Which really just to test that it works. The def func is a callback for the flickr.upload() function.
to upload just call flickr.upload with the right parameter. That is simple.

Seems that there is a lot more. Looks like i will be very busy indeed.

this is the python flickr api, the tutorial, and download is here:
http://flickrapi.sourceforge.net/
the api released by flickr:
http://www.flickr.com/services/api/

No comments:

Post a Comment