I wanted to post automatically from python to twitter, so I investigated the posting method using twitter API and API cooperation library. python uses 3.x series.
Register a new app on the following site for app developers. Twitter Application Management
Get the key and access token you need and make a note of it.
There is a twitter API cooperation library for python. This time, I used the following simple library. sixohsix/twitter
#Install pip (without pip)
easy_install pip
#Install the library using pip
pip install twitter
twitter_post_sample.py
#coding: UTF-8
import twitter
#Set the obtained key and access token
auth = twitter.OAuth(consumer_key="XXX",
consumer_secret="XXX",
token="XXX",
token_secret="XXX")
t = twitter.Twitter(auth=auth)
#Post a message to twitter
t.statuses.update(status="This is a post test from python to twitter!")
Recommended Posts