简体   繁体   中英

Twitter API Get Tweet ID

I'm using an auto poster to post news stories to the Twitter account using the Twitter API 1.1.

I have a slight problem though... If there is something wrong with the news story and it is deleted, I need to be able to delete the tweet automatically.

To do this, I thought that if I can get the ID of the tweet and store it in the database, I could delete it this way, but I can't seem to get the ID of the actual tweet as it tweets if that makes sense? The best way I could find was to use the API to search the Twitter account and get the latest tweet, but there's a risk that the latest tweet is not the actual tweet.

I had a look through the API documentation and there's nothing that I can see that enables you to return the tweet ID. I also looked on here, this was the closest I got: How to get id of the tweet But again, it searches rather than returns the specific ID.

You can POST your tweets to the post/statuses/update endpoint.

You can then read ID as id_str in the response dictionary.

If you are using node.js, you could use

    var params = {status:"This is a dummy tweet to get the current tweet ID. Time:" + currTime};
    client.post('statuses/update', params, function(error, tweets, response){
  if (!error) {
    console.log(tweets.id);
    tweetid = tweets.id;

  }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM