4.2 KiB
Open Photo API / Python Library
OpenPhoto, a photo service for the masses
Installation
python setup.py install
How to use the library
To use the library you need to first import openphoto
, then instantiate an instance of the class and start making calls.
You can use the library in one of two ways:
- Direct GET/POST calls to the server
- Access via Python classes/methods
Direct GET/POST:
from openphoto import OpenPhoto
client = OpenPhoto(host, consumerKey, consumerSecret, token, tokenSecret)
resp = client.get("/photos/list.json")
resp = client.post("/photo/62/update.json", tags=["tag1", "tag2"])
Python classes/methods
from openphoto import OpenPhoto
client = OpenPhoto(host, consumerKey, consumerSecret, token, tokenSecret)
photos = client.photos.list()
photos[0].update(tags=["tag1", "tag2"])
print photos[0].tags
The OpenPhoto Python class hierarchy mirrors the OpenPhoto API endpoint layout. For example, the calls in the example above use the following API endpoints:
- client.photos.list() -> /photos/list.json
- photos[0].update() -> /photo/<id>/update.json
Using from the command line
When using the command line tool, you'll want to export your authentication credentials to the environment. The command line tool will look for the following config file in ~/.config/openphoto/default (the -c switch lets you specify a different config file):
# ~/.config/openphoto/default
host = your.host.com
consumerKey = your_consumer_key
consumerSecret = your_consumer_secret
token = your_access_token
tokenSecret = your_access_token_secret
Click here for instructions on getting credentials.
These are the options you can pass to the shell program.
-h # display help text
-c config_file # Either the name of a config file in ~/.config/openphoto/
# or a full path to a config file
-H hostname # default=localhost
-e endpoint # default=/photos/list.json
-X method # default=GET
-F params # i.e. -F 'title=my title' -F 'tags=mytag1,mytag1'
-p # pretty print the json
-v # verbose output
Now you can run commands to the OpenPhoto API from your shell!
openphoto -H current.openphoto.me -p -e /photo/62/view.json -F 'returnSizes=20x20'
{
"message" : "Photo 62",
"code" : 200,
"result" : {
"tags" : [
],
"id" : "62",
"appId" : "current.openphoto.me",
"pathBase" : "\/base\/201108\/1312956581-opmeqViHrD.jpg",
"dateUploadedMonth" : "08",
"dateTakenMonth" : "08",
"exifCameraMake" : "",
"dateTaken" : "1312956581",
"title" : "Tomorrowland Main Stage 2011",
"height" : "968",
"description" : "",
"creativeCommons" : "BY-NC",
"dateTakenYear" : "2011",
"dateUploadedDay" : "09",
"longitude" : "4",
"host" : "opmecurrent.s3.amazonaws.com",
"hash" : "0455675a8c42148238b81ed1d8db655c45ae055a",
"status" : "1",
"width" : "1296",
"dateTakenDay" : "09",
"permission" : "1",
"pathOriginal" : "\/original\/201108\/1312956581-opmeqViHrD.jpg",
"size" : "325",
"dateUploadedYear" : "2011",
"views" : "0",
"latitude" : "50.8333",
"dateUploaded" : "1312956583",
"exifCameraModel" : "",
"Name" : "62",
"path20x20" : "http:\/\/current.openphoto.me\/photo\/62\/create\/ceb90\/20x20.jpg"
}
}
Getting your credentials
You can get your credentals by clicking on the arrow next to your email address once you're logged into your site and then clicking on settings.
If you don't have any credentials then you can create one for yourself by going to /v1/oauth/flow
.
Once completed go back to the settings page and you should see the credential you just created