LoginSignup
2
3

More than 5 years have passed since last update.

Tweepyを使って、指定したユーザーがフォローしている人を全部フォローする

Posted at

全フォロー君

説明

指定したユーザーがフォローしている人を全部フォローできる。

コード

addUser.py
CONSUMER_KEY = ""
CONSUMER_SECRET = ""
ACCESS_KEY = ""
ACCESS_SECRET = ""
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)

#APIインスタンスを作成
api = tweepy.API(auth)
userid = "" #ここに自分のuseridを入れる
targetid = "" #フォロワーが欲しいユーザーのuseridを入れる
following_id = api.friends_ids(userid) #自分のアカウントのフォロイングをすべて取得する
target_following_id = api.friends_ids(targetid)#ターゲットのアカウントのフォロイングを全て取得する
for target_following in target_following_id:
   if target_following not in following_id: #ターゲットがフォローしているユーザーだけ取得する
     print("フォローするユーザー名")
     targetname = api.get_user(target_following).name
     print(targetname)
     api.create_friendship(target_following)
2
3
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
2
3