Rishikant181 / Rettiwt-API

A CLI tool and an API for fetching data from Twitter for free!
https://rishikant181.github.io/Rettiwt-API/
MIT License
319 stars 32 forks source link

getTweets not working - "Error: BadRequest" #305

Closed jonaslsaa closed 1 year ago

jonaslsaa commented 1 year ago

The login method for getting tweets was working great for a few days, now it is no longer working. I've tried using the same tokens and also logging each time, both give me the following error:

Server Error
Error: BadRequest

This error happened while generating the page. Any console logs will be displayed in the terminal window.
Call Stack
FetcherService.handleHTTPError
./node_modules/rettiwt-api/dist/services/util/FetcherService.js (123:19)
<unknown>
./node_modules/rettiwt-api/dist/services/util/FetcherService.js (178:123)

It occurs when trying to get a batch of tweets from accounts using tweetService.getTweets with a filter. Code snippet:

const loginDetails = await Rettiwt().account.login(env.TW_EMAIL, env.TW_USERNAME, env.TW_PASSWORD);
console.log('Logged in to Twitter');
const rettiwt = Rettiwt(loginDetails);
const tweetService = rettiwt.tweets;
const tweetFilter = new TweetFilter({fromUsers: usersToScrapeList, startDate: startOfSearch.toISOString()});
console.log('Fetching tweets from ' + startOfSearch.toISOString());
const tweets: MyTweet[] = [];
let nextCursor: string | undefined = undefined;
let i = 0;
do {
  await new Promise(r => setTimeout(r, 1000)); // Sleep for 1 second between batches
  // ERROR: BadRequest - following line crashes
  const tweetBatch: {next: {value: string}, list: Tweet[]} = await tweetService.getTweets(tweetFilter, 18, nextCursor);
...
Rishikant181 commented 1 year ago

Due to changes in Twitter APIs, we had to make some necessary changes in the package too. Please update to the latest version and see if the issue persists.

jonaslsaa commented 1 year ago

Looks like I am using the latest version on npm, 1.1.8

Rishikant181 commented 1 year ago

Can you check if any data actually gets stored in loginDetails?

jonaslsaa commented 1 year ago

Yes, data seems valid, in following format:

{
  kdt: '...',
  twid: '"..."',
  ct0: '...',
  auth_token: '...'
}
jonaslsaa commented 1 year ago

What I've tried:

Rishikant181 commented 1 year ago

Can you provide the userToScrape list and startOfSearch for debug purpose?

It seems there might be some issue related to request data not being available or something like that. So without the data set, it will not be possible to reproduce the issue

jonaslsaa commented 1 year ago

These are the filters

{
  "fromUsers": [
    "politietsorost",
    "oslopolitiops",
    "politietost",
    "politietsorvest",
    "politiagder",
    "politiinnlandet",
    "politinordland",
    "politifinnmark",
    "PolitiTrondelag",
    "PolitiMRpd",
    "politivest",
    "polititroms",
    "110Vest",
    "110Bodo",
    "110Innlandet",
    "sorost110",
    "Oslo110sentral",
    "110sorvest",
    "110agder"
  ],
  "startDate": "2023-05-04T03:58:54.095Z"
}
Rishikant181 commented 1 year ago

Sorry for the late reply. I was busy with my semester exams and thankfully, I'm not dead (yet) /s.

I tried to replicate this, but (un)fortunately, this works on my pc. Did you try logging in to you Twitter account from the browser to see whether you can log in?

jonaslsaa commented 1 year ago

No worries! There is no problem logging in to my account on the website. I'll look into it more closely soon (a few days left of my semester), is there anything else I should test then?