desmondmorris / node-twitter

Client library for the Twitter REST and Streaming API's.
https://www.npmjs.com/package/twitter
MIT License
1.27k stars 237 forks source link

Can't use retweet twitter API from node.js - error code 34 #231

Closed z0ph closed 7 years ago

z0ph commented 7 years ago

Hello,

I'm trying to figure out of a simple node.js script to retweet using Twitter API. I was able to create favorites, post status, but a simple retweet is not working.

// rt.js
var Twitter = require('twitter');
var config = require('./config.js');
var T = new Twitter(config);

T.post('statuses/retweet/:id', {
  id: '870436914322472960'
}, (err, data, response) => {
  if (err) {
    console.log(err)
  } else {
    console.log(`${data.text} retweet success!`)
  }
})

The error message is :

[ { message: 'Sorry, that page does not exist', code: 34 } ]

I'm using : twitter@1.7.0 (from npm list)

Thanks for your help.

JulienSol commented 7 years ago

Hello,

You simply have to replace :id with your if :

T.post('statuses/retweet/' + 870436914322472960, '',  (err, data, response) => {
  if (err) {
    console.log(err)
  } else {
    console.log(`${data.text} retweet success!`)
  }
}) 
z0ph commented 7 years ago

Hi @JulienSol

Strange, my id is passed with the following variable, don't need to hardcode it. But whatever, i've tried your code sample, with two different id :

[ { code: 144, message: 'No status found with that ID.' } ]

Thanks for your help,

JulienSol commented 7 years ago

Ah ! Yes, you have to convert id to string :

T.post('statuses/retweet/' + '870436914322472960', (err, data, response) => {
    if (err) {
        console.log(err)
    } else {
        console.log(`${data.text} retweet success!`)
    }
});
z0ph commented 7 years ago

@JulienSol It's working, thanks