ttezel / twit

Twitter API Client for node (REST & Streaming API)
4.31k stars 568 forks source link

404 at id, code 34 #488

Closed viglioni closed 5 years ago

viglioni commented 5 years ago

Hello

I am trying to unfollow accounts given their id.

First step i get all the people that I follow:

function getFriends(){
    return new Promise( (resolve,reject) => {
    T.get('friends/ids', (err,data) => {
        if(err){ reject(err); }
        else{ resolve(data.ids);}
    });
    }).then(result => result);
} 

where T is my Twit object. And this part works perfectly.

Then I try to unfollow some of these ids using this method, after the resolution of the promise, of course:

function kill(friend_id){
    T.post('friendships/destroy', {id: friend_id},
       (err,data) => {
           if(err){  console.log(err.message + " Id: " + friend_id); }
           else{ console.log("unfollowed "+ data.screen_name); }
       });
}

The strangest part is: it worked for some of the id's that i have tried and did not for others. This is the error message i get:

[...]
Sorry, that page does not exist. Id: 905252938028908500
Sorry, that page does not exist. Id: 967554835812962300
Sorry, that page does not exist. Id: 1008065312883970000
Sorry, that page does not exist. Id: 945496245530869800
Sorry, that page does not exist. Id: 1015044288600854500
Sorry, that page does not exist. Id: 981656935744331800
Sorry, that page does not exist. Id: 1025861711587430400
Sorry, that page does not exist. Id: 960127220764282900
Sorry, that page does not exist. Id: 980077548158816300
Sorry, that page does not exist. Id: 984802419203813400
Sorry, that page does not exist. Id: 707707526058549200

The full error message is:

{ Error: Sorry, that page does not exist.
    at Object.exports.makeTwitError (/home/laura/Desktop/tscr/node_modules/twit/lib/helpers.js:74:13)
    at onRequestComplete (/home/laura/Desktop/tscr/node_modules/twit/lib/twitter.js:344:25)
    at Request.<anonymous> (/home/laura/Desktop/tscr/node_modules/twit/lib/twitter.js:364:7)
    at emitOne (events.js:121:20)
    at Request.emit (events.js:211:7)
    at Gunzip.<anonymous> (/home/laura/Desktop/tscr/node_modules/request/request.js:1083:12)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:111:20)
    at Gunzip.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:139:11)
    at process._tickCallback (internal/process/next_tick.js:181:9)
  message: 'Sorry, that page does not exist.',
  code: 34,
  allErrors: [ { code: 34, message: 'Sorry, that page does not exist.' } ],
  twitterReply: { errors: [ [Object] ] },
  statusCode: 404 }

Thanks in advance!

tarngerine commented 5 years ago

I ran into something similar, where the user IDs were getting mangled in the requests when they were sent as ints/numbers: https://stackoverflow.com/questions/47188449/json-max-int-number/47188576.

You can see the similar issue in your error logs, where two zeroes 00 are being appended to your IDs.

~The solution was to turn the IDs into strings when sending the requests (String(friend_id) or ''+friend_id), probably when you store them from the friends/ids call so you're always working with IDs as strings in your code.~ (See reply below for better way using stringify_ids when fetching from friends/ids)

tarngerine commented 5 years ago

Actually, you can just request that all IDs are stringified when you request them like so:

  twit.get('friends/ids', {
    stringify_ids: true
  })
viglioni commented 5 years ago
twit.get('friends/ids', {
    stringify_ids: true
  })

This worked just fine!!! Thank you!

I am closing this issue :)