--I wanted to touch the Twitter API
Consumer Key
and Consumer secret
from the key and access tokenpip install tweepy
Consumer Key
and Consumer secret
in variables respectively.!/usr/bin/python
-*- coding: utf-8 -*-
import tweepy
consumer_key = ""#access https://apps.twitter.com/ and get consumer key
consumer_secret = ""
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
print("Access this URL:" + auth.get_authorization_url())
verifier = raw_input('Verifier:')
auth.get_access_token(verifier)
print "Access Token:", auth.access_token
print "Access Token Secret:", auth.access_token_secret
and ʻAccess Token Secret
, so make a note of each again.!/usr/bin/env python
-*- coding:utf-8 -*-
import tweepy
import datetime
class Listener(tweepy.StreamListener):
def on_status(self, status):
status.created_at += datetime.timedelta(hours=9)
#favo when reply
if str(status.in_reply_to_screen_name)==Twitter_ID and str(status.user.screen_name)!=Twitter_ID:
print(str(datetime.datetime.today()))
api.create_favorite(status.id)
return True
def on_error(self, status_code):
print('Error code:' + str(status_code))
return True
def on_timeout(self):
print('Timeout error')
return True
consumer_key = ""#access s and get consumer key
consumer_secret = ""
access_token = ""
access_secret = ""
Twitter_ID = ""#Your TwitterID(Don't need @)
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
api = tweepy.API(auth)
listener = Listener()
stream = tweepy.Stream(auth, listener)
stream.userstream()
――As mentioned above, the API is easy to use and anyone can easily create a bot.