Skip to content

Instantly share code, notes, and snippets.

@tajuszk
Last active April 21, 2022 05:50
Show Gist options
  • Save tajuszk/9d001c91e226c3949b2f884b6b794205 to your computer and use it in GitHub Desktop.
Save tajuszk/9d001c91e226c3949b2f884b6b794205 to your computer and use it in GitHub Desktop.
/**
* ③最新のツイートをリツイートする
*/
function retweetLatest () {
// 最新のツイートのツイートIDを取得する
const accountName = 'belltreeszk' // 対象のアカウントの @~~~~ の部分を記入
const includeRT = false // RTを含むか(他のユーザーのツイートのRTも再度RTします)
const retweetCount = 3 // 直近何件のツイートをRTするか
const tweetIds = client.pickupTweetsLatest(accountName, includeRT, retweetCount);
// URLが含まれているものを除く
const tweetShowUrl = 'https://api.twitter.com/1.1/statuses/show.json';
for (let i = tweetIds.length - 1; i >= 0; i--) {
const tweetShowParam = {
id: tweetIds[i],
}
const tweetShowResult = client.getRequest(tweetShowUrl, tweetShowParam);
// ここでURLの有無をチェック
if (tweetShowResult.entities.urls.length > 0) {
tweetIds.splice(i, 1);
}
}
// 受け取ったツイートIDのツイートをすべてリツイートする
client.retweet(tweetIds)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment