Tweet With Image, Using Python / Pythonで画像ツイートをする

 In this time, let's try posting tweet with image.

 

To tweet with image, you need Twitter API, so first you have to apply API toTwitter(https://developer.twitter.com/).

 

Previously it was hard to get Twitter API,  it took about 10days, but in 2019 Twitter changes rules, so it gets easier than before.

 

The whole source code is below.

Tweet With Image In Python

 

In the first, you must write defintion to access twitter in the head of code. API is very significant, be careful not to let anyone  know. There is risk that malicious man hijack your Twitter account.

 

To read json and use oauthsession, declare the next.

import json
from requests_oauthlib import OAuth1Session

 

write consumer key,access token and so on.

#definition to connect to Twitter
CONSUMER_KEY = "***********************************"
CONSUMER_SECRET = "***********************************"
ACCESS_TOKEN = "***********************************"
ACCESS_TOKEN_SECRET = "***********************************"

 

 

Run file, you will see post like the follow.

f:id:astrophysik928:20190810103008p:plain