Post images from Python to Tumblr

Preparation

Install library

Install it because it uses python-tumblpy which can also be used with python3.

pip install python-tumblpy

Get KEY

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.

the first stage

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)

Second stage

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)

Post test

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

Post images from Python to Tumblr
Post from Python to Slack
Post from python to facebook timeline
[Lambda] [Python] Post to Twitter from Lambda!
Changes from Python 3.0 to Python 3.5
Changes from Python 2 to Python 3.0
POST images from ESP32-CAM (MicroPython) to the server
Post to vim → Python → Slack
Cheating from PHP to Python
Post to slack with Python 3
Anaconda updated from 4.2.0 to 4.3.0 (python3.5 updated to python3.6)
Switch from python2.7 to python3.6 (centos7)
Connect to sqlite from python
Post to Slack in Python
POST messages from python to Slack via incoming webhook
Call Matlab from Python to optimize
How to collect images in Python
Extract text from images in Python
Connect to utf8mb4 database from python
Post multiple Twitter images with python
Python (from first time to execution)
How to access wikipedia from python
Python to switch from another language
Easily post to twitter with Python 3
[Nanonets] How to post Memo [Python]
Did not change from Python 2 to 3
Update Python on Mac from 2 to 3
Python OCR System Raise characters from images to improve work efficiency
Post a message from IBM Cloud Functions to Slack in Python
[Python] Try to recognize characters from images with OpenCV and pyocr
[Python] Fluid simulation: From linear to non-linear
From Python to using MeCab (and CaboCha)
How to update Google Sheets from Python
Send a message from Python to Slack
Private Python handbook (updated from time to time)
Convert from katakana to vowel kana [python]
Push notification from Python server to Android
Function to save images by date [python3]
Connecting from python to MySQL on CentOS 6.4
Porting and modifying doublet-solver from python2 to python3.
How to access RDS from Lambda (python)
Download images from URL list in Python
Python> Output numbers from 1 to 100, 501 to 600> For csv
Add Gaussian noise to images with python2.7
Convert from Markdown to HTML in Python
[Amazon Linux] Switching from Python 2 series to Python 3 series
API explanation to touch mastodon from python
Upload images to Google Drive with Python
Connect to coincheck's Websocket API from Python
[Python] (Line) Extract values from graph images
Updated to Python 2.7.9
Sum from 1 to 10
sql from python
MeCab from Python
"Backport" to python 2
[Python] Download original images from Google Image Search
Edit Excel from Python to create a PivotTable
How to open a web browser from python
Image characters and post to slack (python slackbot)
Convert PDFs to images in bulk with Python
[Python] Convert from DICOM to PNG or CSV