A Python Library to interface with Tumblr v2 REST API & OAuth
Project description
Tumblpy is a Python library to help interface with Tumblr v2 REST API & OAuth
Features
Retrieve user information and blog information
- Common Tumblr methods
Posting blog posts
Unfollowing/following blogs
Edit/delete/reblog posts
And many more!!
Photo Uploading
Installation
Installing Tumbply is simple:
$ pip install python-tumblpy
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 t = Tumblpy(app_key = '*your app key*', app_secret = '*your app secret*', oauth_token=oauth_token, oauth_token_secret=oauth_token_secret) # In Django, you'd do something like # oauth_verifier = request.GET.get('oauth_verifier') oauth_verifier = *Grab oauth verifier from URL* authorized_tokens = t.get_access_token(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 some User information
# Get the final tokens from the database or wherever you have them stored t = Tumblpy(app_key = '*your app key*', app_secret = '*your app secret*', oauth_token=final_tokens['oauth_token'], oauth_token_secret=final_tokens['oauth_token_secret']) # Print out the user info, let's get the first blog url... blog_url = t.post('user/info') blog_url = blog_url['user']['blogs'][0]['url']
Getting posts from a certain blog
# Assume you are using the blog_url and Tumblpy instance from the previous section posts = t.get('posts', blog_url=blog_url) print posts
Creating a post with a photo
# Assume you are using the blog_url and Tumblpy instance from the previous sections files = open('/path/to/file/image.png', 'rb') post = t.post('post', blog_url=blog_url, params={'type':'photo', 'caption': 'Test Caption'}, files=files) print post
Following a user
# Assume you are using the blog_url and Tumblpy instance from the previous sections try: follow = t.post('user/follow', params={'url': 'omglegit.tumblr.com'}) except TumblpyError: # if the url given in params is not valid, # Tumblr will respond with a 404 and Tumblpy will raise a TumblpyError
Catching errors
try: t.post('user/info') except TumbplyError, e: print e.message print 'Something bad happened :('
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
python-tumblpy-0.4.0.tar.gz
(6.6 kB
view hashes)