Last active
March 21, 2021 07:55
-
-
Save tajuszk/ff2181873904d8f1050cbdb6f8634404 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 retweetLatest () { | |
// https://developer.twitter.com/en/docs/twitter-api/v1/accounts-and-users/create-manage-lists/api-reference/get-lists-members | |
// というAPIを使ってリストのメンバー一覧を取得する | |
const listId = '*************' // リストのURLの https://twitter.com/i/lists/******** ←の数字 | |
const listMemberUrl = 'https://api.twitter.com/1.1/lists/members.json'; | |
const listMemberParam = { | |
list_id: listId, | |
} | |
const listResult = client.getRequest(listMemberUrl, listMemberParam) | |
// APIでユーザーの情報を取ってきたら for を使って、必要な情報だけを accountNames という配列に入れる | |
const accountNames = []; | |
for (let i in listResult.users) { | |
const user = listResult.users[i]; | |
accountNames.push(user.screen_name); | |
} | |
// 以下複数のユーザーを対象にRTする処理を実行 | |
let tweetIdsAllUsers = []; | |
for (let i in accountNames) { | |
const accountName = accountNames[i]; | |
const includeRT = false // RTを含むか(他のユーザーのツイートのRTも再度RTします) | |
const retweetCount = 5 // 直近何件のツイートをRTするか | |
// 一旦すべての tweetIds を tweetIdsAllUsers にまとめる | |
const tweetIds = client.pickupTweetsLatest(accountName, includeRT, retweetCount); | |
tweetIdsAllUsers = tweetIdsAllUsers.concat(tweetIds); | |
} | |
// tweetIdsAllUsers に入っているIDを並び替えする(IDが高いものほど新しいので) | |
tweetIdsAllUser.sort(function (a, b) { | |
return a - b | |
}); | |
client.retweet(tweetIdsAllUser); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment