Rishikant181 / Rettiwt-API

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

Invalid character in header content ["cookie"] #498

Closed randyyu13 closed 6 months ago

randyyu13 commented 6 months ago

When trying to make an api call with API key, I get the following error: Invalid character in header content ["cookie"] I'm assuming there is a break character or something when the API key is parsed, so I tried the following

var token = 'api token here'
token.replace(/\r?\n|\r/g, '')
const rettiwt = new Rettiwt({ apiKey: token });
rettiwt.tweet.list('12345678')

and expectedly I got the same error. Any ideas what is happening and how to fix? Same thing occurs in CLI API key is 207 characters long for reference

Rishikant181 commented 6 months ago

The API_KEY is base64 encoded. As such, these are all the characters that are in it: image

Can you manually inspect the API_KEY to check if it meets these conditions?

randyyu13 commented 6 months ago

It is not base64 encoded, do I generate a new API key or what do you recommend? image

Rishikant181 commented 6 months ago

do I generate a new API key

Yes

randyyu13 commented 6 months ago

That fixed it, thank you

BOXNYC commented 1 month ago

When running the cl to get an API_KEY it only returns {}

So I attempted retrieving it from the browser, by running the cookies in console:

var auth_token = '########',
ct0 = '######',
kdt = '######',
twid = 'u%######'

btoa(`auth_token=${auth_token};ct0=${ct0};kdt=${kdt};twid=${twid}
`).replace(/[^a-zA-Z0-9\+\=\/]/g, '')

I tested the length and characters and validated it online and all is good

But when I test it in creating a stream, I get the same TypeError Invalid char... ...["cookie"] mentioned by randyyu13, which brought me to this issue...

Notes:

Thanks and I'm excited to get this running! LMK what I can do

Rishikant181 commented 1 month ago

When running the cl to get an API_KEY it only returns {}

I do have 2FA set

2FA is not supported, that's why you get '{}'

As for the workaround, did you try to decode the API_KEY using the method atob? What output do you get if you decode it?

BOXNYC commented 1 month ago

Hi, thanks for your help.

I was wrong, I don't have 2FA turned on.

Also, I was able to get the key created through a browser! Thanks! Looks like I have a line break at the end, you can see in the code above. Embarrassing lol

I'll create a new issue if you prefer, but on my first attempt to stream, I get: RettiwtError: TOO_MANY_REQUESTS at HttpError.RettiwtError [as constructor]... status: 429 I researched and found that 429 is a Too Many Requests status code that is commonly used in web networking so do I assume this is coming from the Twitter endpoint.

Are you able to build a @mentions stream? Have you tested it in a while? Wondering if something changed on the Twitter side.

Thanks!

Update: Now when I run it, get RettiwtError: Failed to authenticate Now I'm banned...

Your account is suspended
After careful review, we determined your account broke the [X Rules](https://help.twitter.com/rules-and-policies/twitter-rules). Your account is permanently in read-only mode, which means you can’t post, Repost, or Like content. You won’t be able to create new accounts. If you think we got this wrong, you can [submit an appeal].
Rishikant181 commented 1 month ago

I'll create a new issue if you prefer, but on my first attempt to stream, I get

What polling rate did you use? Remember that stream method sends repeated requests at fixed intervals, defined by the polling rate. If you set it too, low, you might have run into TOO_MANY_REQUESTS

Are you able to build a @mentions stream?

No, unfortunately we can't, since the normal tweet stream is nothing but the search function called at fixed intervals to poll for newer tweets.

Now I'm banned...

Hopefully, it was a burner account?

BOXNYC commented 1 month ago

The pollingInterval was set to 1000, I didn't really even know what that was I just pasted the stream code.

Hah not a burner, was my client's account, bummer. Perhaps they will un-ban.

Thanks for all your help on your amazing API!