Skip to content

Commit

Permalink
Add example
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhelmick committed Feb 8, 2017
1 parent 6ded4c4 commit 21490bd
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions examples/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import sys

from tumblpy import Tumblpy

key = raw_input('App Consumer Key: ')
secret = raw_input('App Consumer Secret: ')

if not 'skip-auth' in sys.argv:
t = Tumblpy(key, secret)

callback_url = raw_input('Callback URL: ')

auth_props = t.get_authentication_tokens(callback_url=callback_url)
auth_url = auth_props['auth_url']

OAUTH_TOKEN_SECRET = auth_props['oauth_token_secret']

print('Connect with Tumblr via: {}'.format(auth_url))

oauth_token = raw_input('OAuth Token (from callback url): ')
oauth_verifier = raw_input('OAuth Verifier (from callback url): ')

t = Tumblpy(key, secret, oauth_token, OAUTH_TOKEN_SECRET)

authorized_tokens = t.get_authorized_tokens(oauth_verifier)

final_oauth_token = authorized_tokens['oauth_token']
final_oauth_token_secret = authorized_tokens['oauth_token_secret']

print('OAuth Token: {}'.format(final_oauth_token))
print('OAuth Token Secret: {}'.format(final_oauth_token_secret))
else:
final_oauth_token = raw_input('OAuth Token: ')
final_oauth_token_secret = raw_input('OAuth Token Secret: ')

t = Tumblpy(key, secret, final_oauth_token, final_oauth_token_secret)

blog_url = t.post('user/info')
blog_url = blog_url['user']['blogs'][0]['url']

print('Your blog url is: {}'.format(blog_url))

posts = t.posts(blog_url)

print('Here are some posts this blog has made:', posts)

# print t.post('post', blog_url=blog_url, params={'type':'text', 'title': 'Test', 'body': 'Lorem ipsum.'})

0 comments on commit 21490bd

Please sign in to comment.