I tried to develop an application to tweet to Twitter in Visual Studio 2017 in Python. This time, I am creating an environment for the project using a virtual environment (venv).
Windows 7 Professional SP1 64bit Visual Studio 2017 Community 15.2 (26430.6) Python 3.6.0 requests-oauthlib 0.8.0
Please refer to here for environment construction and Python project creation. http://qiita.com/akabei/items/a3b8b62f1cf34b683121
Create a "Python application" from a new project.
Create a virtual environment (venv) when developing by changing the environment for each project. Right-click on the Python environment in Solution Explorer and select "Add Virtual Environment ..." from the menu.
A dialog will be displayed. Select the Python version used in the project and create a virtual environment.
A virtual environment "env" is created in the Python environment. The packages are still minimal.
From the project's Python environment, right-click "env (Python 3.6 (64bit))" and select "Install Python Package ...".
Type "requests-oauthlib" in the text box and select "Install requests-oauthlib (0.8.0)" to install the package.
The requests-oauthlib package and its dependent packages are installed in the env virtual environment.
Write the program to tweet in tweet.py. Input completion (intellisense) cannot be used immediately after inserting the package, but it will be available after a while.
tweet.py
from requests_oauthlib import OAuth1Session
CONSUMER_KEY = 'xxxxxx'
CONSUMER_SECRET = 'xxxxxx'
ACCESS_TOKEN = 'xxxxxx'
ACCESS_SECRET = 'xxxxxx'
twitter = OAuth1Session(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_SECRET)
twitter.post("https://api.twitter.com/1.1/statuses/update.json", params={"status": "Tsuto Nau"})
Please run it and check if it was tweeted properly.
Recommended Posts