- フォロワーIDを取得する => 5,000*15で15分で75,000フォロワー取得可能
- IDからユーザーを検索 => 100*900で15分で90,000分のユーザー情報取得可能
Created
January 23, 2018 08:05
-
-
Save yukihirai0505/7f15b67020f9e66b9cce2e4004a83e8e to your computer and use it in GitHub Desktop.
Twitterで特定のユーザーのフォロワー名を全部取得する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OutputTwitterFollower { | |
def outputTwitterFollower = { | |
val targetAccount = "yabaiwebyasan" | |
def getFollower(ids: Seq[Long] = Seq.empty, nextCursor: Long = -1): Future[Seq[Long]] = { | |
twitterClient.followerIdsForUser(targetAccount, nextCursor, 5000).flatMap { result => | |
val _ids = ids ++ result.data.ids | |
val cursor = result.data.next_cursor | |
if (cursor > 0) { | |
print(s"next_cursor: $cursor") | |
getFollower(_ids, cursor) | |
} else { | |
Future successful _ids | |
} | |
} | |
} | |
import java.io.{FileOutputStream => FileStream, OutputStreamWriter => StreamWriter} | |
val fileName = s"$targetAccount.txt" | |
val encode = "UTF-8" | |
val append = true | |
val fileOutPutStream = new FileStream(fileName, append) | |
val writer = new StreamWriter(fileOutPutStream, encode) | |
val ids = Await.result(getFollower(), Duration.Inf) | |
println(s"users by ids request num: ${ids.length}") | |
ids.grouped(100).toSeq.foreach { _ids => | |
val users = Await.result(twitterClient.usersByIds(_ids), Duration.Inf).data | |
users.foreach(u => writer.write(s"${u.screen_name}\n")) | |
} | |
writer.close() | |
Future successful "ok" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment