Created
March 17, 2023 15:19
-
-
Save YogaSakti/0de1286d7a86d4ecef6ad18c0389caef to your computer and use it in GitHub Desktop.
TwitterDev: we are announcing the deprecation of the v1.1 streaming statuses/filter endpoint, with a formal deprecation date of March 9, 2023. This completes the full retirement of v1.1 streaming endpoints (we previously announced the other components in April 2022). We encourage you to begin the migration process to the filtered stream endpoint…
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
const twitter = require('twitter-api-v2') | |
(async () => { | |
const client = new twitter.TwitterApi('YOUR_APP__TOKEN'); | |
// const rules = await client.v2.streamRules(); | |
// delete old rules | |
// if (rules.data?.length) { | |
// await client.v2.updateStreamRules({ | |
// delete: { ids: rules.data.map((rule) => rule.id) } | |
// }); | |
// } | |
// add our rules | |
await client.v2.updateStreamRules({ | |
add: [{ value: 'jokowi' }] | |
}); | |
const twitterFields = [ | |
'author_id', | |
'created_at', | |
'entities', | |
'id', | |
'in_reply_to_user_id', | |
'source', | |
'text' | |
]; | |
const userFields = [ | |
'created_at', | |
'description', | |
'entities', | |
'id', | |
'location', | |
'name', | |
'pinned_tweet_id', | |
'profile_image_url', | |
'protected', | |
'public_metrics', | |
'url', | |
'username', | |
'verified', | |
'verified_type', | |
'withheld' | |
]; | |
// get stream | |
const stream = await client.v2.searchStream({ | |
'tweet.fields': twitterFields, | |
'user.fields': userFields | |
}); | |
// enable auto reconnect | |
stream.autoReconnect = true; | |
// listen to data | |
stream.on(twitter.ETwitterStreamEvent.Data, async (tweet) => { | |
console.log(tweet.data); | |
}); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment