Adding a Twitter Reply via Twitter API
A quick note to self regarding adding a reply on Twitter using Twitter NPM library.
POST statuses/update
POST statuses/update lets one "tweet" a status on Twitter.
But when you want to add a reply the an existing twitter, you can set the in_reply_to_status_id
to the tweet ID you want to reply to.
The documentation for [in_reply_to_status_id](https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-update#parameters)
states that
The ID of an existing status that the update is in reply to. Note: This parameter will be ignored unless the author of the Tweet this parameter references is mentioned within the status text. Therefore, you must include
@username
, whereusername
is the author of the referenced Tweet, within the update.
Even though it says that it should be "mentioned within the status text", but it doesn't sound 100% correct as passing username
mentioned in the following sentence was enough to trigger the reply thread.
const Twitter = require('twitter') | |
const config = { | |
consumer_key: 'secret', | |
consumer_secret: 'secret', | |
access_token_key: 'secret', | |
access_token_secret: 'secret', | |
} | |
const client = new Twitter(config) | |
// https://github.com/desmondmorris/node-twitter#promises | |
const update = (status, in_reply_to_status_id = null) => | |
client.post('statuses/update', { | |
status, | |
in_reply_to_status_id, | |
username: '@dance2die', | |
}) | |
update('Testing twitter NPM library') | |
.then(tweet => { | |
console.log(`tweet #1 ==>`, tweet) | |
return update('Reply #1', tweet.id_str) | |
}) | |
.catch(error => console.log(`error ==>`, error)) |
On line #17, username is passed and that's sufficient to make in_reply_to_status_id
not to be ignored by Twitter.
https://mobile.twitter.com/dance2die/status/1155604901558456321
Webmentions
Loading counts...