Created
December 25, 2021 17:08
-
-
Save tajuszk/8646e46833074f26be383e6af756a9d6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* フォローユーザーをリストに追加する | |
*/ | |
function addFollowUserToList () { | |
// === ここだけ編集してください === | |
// LIST_ID をリストページのURLから取ってくる | |
// 例) https://twitter.com/i/lists/1474779699952119808 ←ここの部分 | |
const LIST_ID = '********'; | |
// ① フォローしている人を取得 | |
const userIds = client.getFollowUserIds(); | |
// ② リストにメンバーを追加するAPIを実効する | |
// 使用するAPI | |
// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/post-lists-members-create_all | |
const apiUrl = 'https://api.twitter.com/1.1/lists/members/create_all.json'; | |
const params = { | |
list_id: LIST_ID, | |
}; | |
// 100人ずつリストに追加する | |
let count = 0; | |
let userIdStr = ''; | |
for (let i in userIds) { | |
count++; | |
userIdStr += userIds[i] + ','; | |
if (count === 100) { | |
params['user_id'] = userIdStr; | |
client.postRequest(apiUrl, params); // 100人分たまったのでAPI実行 | |
// countとuserIdStrをリセット | |
count = 0; | |
userIdStr = ''; | |
} | |
} | |
params['user_id'] = userIdStr; | |
client.postRequest(apiUrl, params); // 余った人もAPI実行 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment