LoginSignup
0
0

More than 3 years have passed since last update.

Twitter api Python 自動化(自分用メモ)

Last updated at Posted at 2020-09-13

コピペ用

CONFIG = {
"CONSUMER_KEY":"自分の",
"CONSUMER_SECRET":"自分の",
"ACCESS_TOKEN":"自分の",
"ACCESS_SECRET":"自分の",
}

import tweepy
import time

CONSUMER_KEY = CONFIG["CONSUMER_KEY"]
CONSUMER_SECRET = CONFIG["CONSUMER_SECRET"]
ACCESS_TOKEN = CONFIG["ACCESS_TOKEN"]
ACCESS_SECRET = CONFIG["ACCESS_SECRET"]

q_list = ["検索するKW"]
count = 100

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)
api = tweepy.API(auth)

for q in q_list:
search_results = api.search(q=q, count=count)
for result in search_results:
time.sleep(10)
tweet_id = result.id #Tweetのidを取得
user_id = result.user._json['id'] #ユーザーのidを取得
try:
api.create_favorite(tweet_id) #ファボする
#api.retweet(tweet_id)
#api.create_friendship(user_id) #フォローする
except Exception as e:
print(e)

終わり

とりあえず「いいね」を送ることだけはできる。429エラーを吐く原因と対処がわからないためいったん放置。
普段はブログで情報発信してるので暇な日とは読んでみてね。
URL:https://www.ivyblog.org/

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0