Install it because it uses python-tumblpy which can also be used with python3.
pip install python-tumblpy
Register Tumblr app to get OAuth Consumer Key and Secret Key. The Application website and Default callback URL are tumblr blogs prepared for posting images.
Run the following script to access the output auth_url with a browser and allow it. Then, the URL is skipped, and there is oauth_verifier in the query parameter of the URL to which it was skipped. Make a note of it.
first.py
from tumblpy import Tumblpy
CONSUMER_KEY = 'The one I got'
CONSUMER_SECRET = 'The one I got'
t = Tumblpy(CONSUMER_KEY, CONSUMER_SECRET)
auth_props = t.get_authentication_tokens()
auth_url = auth_props['auth_url']
OAUTH_TOKEN = auth_props['oauth_token']
OAUTH_TOKEN_SECRET = auth_props['oauth_token_secret']
print(auth_url)
print(OAUTH_TOKEN)
print(OAUTH_TOKEN_SECRET)
Using OAUTH_TOKEN, OAUTH_TOKEN_SECRET, oauth_verifier acquired in the first stage Execute the following script. Use the two tokens obtained from this script for posting.
second.py
from tumblpy import Tumblpy
CONSUMER_KEY = 'The previous one'
CONSUMER_SECRET = 'The previous one'
OAUTH_TOKEN = 'The one I got'
OAUTH_TOKEN_SECRET = 'The one I got'
t = Tumblpy(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
oauth_verifier = 'URL parameter guy'
authorized_tokens = t.get_authorized_tokens(oauth_verifier)
oauth_token = authorized_tokens['oauth_token']
oauth_token_secret = authorized_tokens['oauth_token_secret']
print(oauth_token)
print(oauth_token_secret)
Try posting a local sample.jpg. Posting is complete when the post id is displayed.
test.py
from tumblpy import Tumblpy
CONSUMER_KEY = 'The previous one'
CONSUMER_SECRET = 'The previous one'
OAUTH_TOKEN = 'The one I got before'
OAUTH_TOKEN_SECRET = 'The one I got before'
t = Tumblpy(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
blog_url = 'URL of tumblr to post'
photo = open('sample.jpg', 'rb')
post = t.post('post', blog_url=blog_url, params={'type':'photo', 'caption': 'Test Caption', 'data': photo})
print(post)
Recommended Posts