Try using the Twitter API

I had something I wanted to do using the Twitter API, so I will leave a self-learning memo about how to use the API used this time.

version

Write down each version of the environment and tools used this time. python: 3.8.2 (pyenv: 1.2.18) pip: 20.0.2 tweepy: 3.8.0 (Maybe the dependencies:  PySocks-1.7.1  certifi-2020.4.5.1  chardet-3.0.4  idna-2.9  oauthlib-3.1.0  requests-2.23.0  requests-oauthlib-1.3.0  six-1.14.0  tweepy-3.8.0  urllib3-1.25.9)

Setup record

It's a memo of the record I followed, so I don't know. (I started with what is pip this time)

I referred to it in the Python environment settings. https://prog-8.com/docs/python-env There is even such support. I thought Progate was a great service (small average feeling). Thank you very much.

I also understand pip well. Since it was a Mac, it moved on its own. https://gammasoft.jp/python/python-library-install/

Developer registration for Twitter API

I did most of it with reference to the following article. https://qiita.com/kngsym2018/items/2524d21455aac111cdee https://www.torikun.com/entry/twitter-developer-api/

(Sieve, API Japanese) http://westplain.sakuraweb.com/translate/twitter/Documentation/REST-APIs/Public-API/The-Search-API.cgi

Use tweepy

I decided to use a library called tweepy. http://docs.tweepy.org/en/latest/install.html

The reason is that I was caught in the search, and there may be a library that is easier to use related to other twitter APIs. There seems to be OAuth 1a authentication, but I will not use it this time

First, proceed as described in Getting Start.

import tweepy

consumer_key = 'consumer_key'
consumer_secret = 'consumer_secret'
access_token = 'access_token'
access_token_secret = 'access_token_secret'

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)

public_tweets = api.home_timeline()
for tweet in public_tweets:
    print('-------------------------')
    print(tweet.text)

api.update_status("TEST post from tweepy [get timeline complete] ")

In this operation check. Get TimeLine for the time being, and check the operation until posting when the processing is completed.

Next, let's execute an example of getting user information of a specific id. The following processing has been added.

# Get the User object for twitter...
user = api.get_user('zooshima_k')

print(user.screen_name)
print(user.followers_count)
for friend in user.friends():
   print(friend.screen_name)

** Result ↓ **

zooshima_k
188
・ ・ ・ ・ (List of friend names)

I tried it with my account, but it came out brilliantly. You will see the number of followers and the names of the users you are following. It's interesting.

After this, I expected that Steraming would bring information. Unfortunately, it hasn't been possible since 2018. sad···

I had something I wanted to do, but I gave up. This is the end of the article. I may update it again when I can do something.

Recommended Posts

Try using the Twitter API
Try using the PeeringDB 2.0 API
Try using the Wunderlist API in Python
Try using the Kraken API in Python
Tweet using the Twitter API in Python
Try using the BitFlyer Ligntning API in Python
Try using the DropBox Core API in Python
Try drawing a social graph using Twitter API v2
Try to delete tweets in bulk using Twitter API
Post to your account using the API on Twitter
Try using Janus gateway's Admin API
Specifying the date with the Twitter API
Try using Pleasant's API (python / FastAPI)
Try using Python argparse's action API
Try using the Python Cmd module
Access the Twitter API in Python
I tried using the checkio API
Try hitting the Twitter API quickly and easily with Python
Create a real-time auto-reply bot using the Twitter Streaming API
Tweet Now Playing to Twitter using the Spotify API. [Python]
For the time being, try using the docomo chat dialogue API
Try using Tkinter
Try using docker-py
I tried using Twitter api and Line api
Try using the web application framework Flask
Try using the $ 6 discount LiDAR (Camsense X1)
Try using the HL band in order
Try using cookiecutter
Try using PDFMiner
Try using the camera with Python's OpenCV
Try the Microsoft Cognitive Services Face API
Try using geopandas
Try using Dropbox API v2 with Go
Try using Selenium
Try cluster analysis using the K-means method
Create an application using the Spotify API
Try using pandas.DataFrame
Try using django-swiftbrowser
Try using matplotlib
Try hitting the YouTube API in Python
Try using tf.metrics
Play with puns using the COTOHA API
Try using PyODE
Try hitting the Spotify API in Django.
Record custom events using the Shotgun API
I tried using the BigQuery Storage API
Tweet regularly with the Go language Twitter API
I checked the library for using the Gracenote API
Hit the Web API using requests Example: Flickr
Python: Try using the UI on Pythonista 3 on iPad
Try using the Chinese morphological analysis engine jieba
I tried using the Google Cloud Vision API
Try using LINE Notify for the time being
Try using the collections module (ChainMap) of python3
Try using kabu station API of kabu.com Securities
Try using the Python web framework Tornado Part 2
Try accessing the YQL API directly from Python 3
Try using ChatWork API and Qiita API in Python
Try using virtualenv (virtualenvwrapper)
[Azure] Try using Azure Functions
Try using virtualenv now