A Python Library to interface with Flickr REST API, OAuth & JSON Responses
Project description
Python-Flickr is A Python library to interface with Flickr REST API & OAuth
Features
Photo Uploading
Retrieve user information
- Common Flickr methods
Add/edit/delete comments
Add/edit/delete notes
And many more (very dynamic library)!!
All responses return as nice dicts
Installation
Installing Python-Flickr is simple:
$ pip install python-flickr
Usage
Handling the Callback
# oauth_token and oauth_token_secret come from the previous step
# if needed, store those in a session variable or something
f = FlickrAPI(api_key='*your app key*',
api_secret='*your app secret*',
oauth_token=oauth_token,
oauth_token_secret=oauth_token_secret)
authorized_tokens = f.get_auth_tokens(oauth_verifier)
final_oauth_token = authorized_tokens['oauth_token']
final_oauth_token_secret = authorized_tokens['oauth_token_secret']
# Save those tokens to the database for a later use?
Getting the Users recent activity feed
# Get the final tokens from the database or wherever you have them stored
f = FlickrAPI(api_key='*your app key*',
api_secret='*your app secret*',
oauth_token=final_tokens['oauth_token'],
oauth_token_secret=final_tokens['oauth_token_secret'])
recent_activity = f.get('flickr.activity.userComments')
print recent_activity
Add comment on a photo
# Assume you are using the FlickrAPI instance from the previous section
add_comment = f.post('flickr.photos.comments.addComment',
params={'photo_id': '6620847285', 'comment_text': 'This is a test comment.'})
#This returns the comment id if successful.
print add_comment
Remove comment on a photo
# Assume you are using the FlickrAPI instance from the previous section
# If the comment is already deleted, it will throw a FlickrAPIError (In this case, with code 2: Comment not found.)
del_comment = f.post('flickr.photos.comments.deleteComment', params={'comment_id':'45887890-6620847285-72157628767110559'})
print del_comment
Upload a photo
# Assume you are using the FlickrAPI instance from the previous section
files = open('/path/to/file/image.jpg', 'rb')
add_photo = f.post(params={'title':'Test Title!'}, files=files)
print add_photo # Returns the photo id of the newly added photo
Catching errors
# Assume you are using the FlickrAPI instance from the previous section
try:
# This comment was already deleted
del_comment = f.post('flickr.photos.comments.deleteComment', params={'comment_id':'45887890-6620847285-72157628767110559'})
except FlickrAPIError, e:
print e.msg
print e.code
print 'Something bad happened :('
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
python-flickr-0.3.2.tar.gz
(6.7 kB
view details)
File details
Details for the file python-flickr-0.3.2.tar.gz.
File metadata
- Download URL: python-flickr-0.3.2.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
597962bb072d47b7b396cd999f37611fea33da02f14a168e7e3726fc7c12320a
|
|
| MD5 |
d261a495735b419cf952d0d66e3a91b2
|
|
| BLAKE2b-256 |
7075832a2c70df7b8b1c22d96cdf3df9bb801010b446ec2e8dd7cae3bb55e59a
|