twitter4r その2
例のBotがFollowされるたびに、手動でFollowをする必要があった*1ので、twitter4rのfriend関連の機能を使って、自動Followを実装してみた。
def follow(friend_name) config_file = File::join(File.dirname(__FILE__), "conf_m.yaml") twitter = Twitter::Client.from_config(config_file, "prod") fri = twitter.my(:friends) fri.each { |user| return if user.screen_name == friend_name } twitter.friend(:add, friend_name) end
ログインしているところは前と同じ。my(:friends)でログインユーザのFollowing一覧を取得して、既に登録している人は弾く。friend(:add, ユーザ名)で指定したユーザをFollowする。
メールサーバを動かしていないので、一定間隔でGMailを見て新規Followerを取得してます。こっちは毎分動かしているわけではないのですぐにFollow返しはできません><
*1:大変けまらしい勢いでした
Leave a Reply