Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Request failed with status code 401 #3

Open
iFrez opened this issue May 13, 2020 · 15 comments
Open

Error: Request failed with status code 401 #3

iFrez opened this issue May 13, 2020 · 15 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@iFrez
Copy link

iFrez commented May 13, 2020

Hello, since yesterday I get an error, everything worked well before!

(node:19218) UnhandledPromiseRejectionWarning: Error: Request failed with status code 401
    at createError (/home/ubuntu/Twitch/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/home/ubuntu/Twitch/node_modules/axios/lib/core/settle.js:18:12)
    at IncomingMessage.handleStreamEnd (/home/ubuntu/Twitch/node_modules/axios/lib/adapters/http.js:202:11)
    at IncomingMessage.emit (events.js:333:22)
    at endReadableNT (_stream_readable.js:1201:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
(node:19218) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag '--unhandled-rejections=strict' (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:19218) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
@whiteworthy
Copy link

did you find a fix for that?

@iFrez
Copy link
Author

iFrez commented May 27, 2020

Since May 1, 2020 all Helix api request require use of OAuth. Read more here https://discuss.dev.twitch.tv/t/requiring-oauth-for-helix-twitch-api-endpoints/23916 . So you need modify script (dist\include\idler.js) to provide Bearer token for each API request.

 function Idler() {
  this.clientId = config.clientId;
  this.userName = config.userName;
  this.userAuth = config.userAuth;
  this.Token = config.token; // Add this

  ...
}

Then for each API calls

...

headers: {  
  'Client-ID': this.clientId,  
  'Authorization': "Bearer " + this.Token   // Add this
}

...

And finaly in your config.json

{
    "clientId": "",
    "userName": "",
    "userAuth": "",
    "token": ""  // Add this
}

@DocksDocks
Copy link

I'm having issues still, can u tell me what specific var refers to?
clientId is from the twitch.dev
token is from the twitch.dev token
userAuth is my password
and username is my username in twitch
Is that it ? If it is i don't know why i am still getting an error.

@DocksDocks
Copy link

error
My error

@iFrez
Copy link
Author

iFrez commented May 27, 2020

{
    "clientId": "", // ID of yuor extention from https://dev.twitch.tv/console/extensions
    "userName": "", // twitch UserName
    "userAuth": "oauth:7cab.......or9",
    "token": "r3jhe1egb6.............uv9oi3x01a"
}

userAuth - Oauth token from Twitch Chat OAuth Password Generator

token - Token generated especially to your clientId. Read more here.

Example url to get app token:

https://id.twitch.tv/oauth2/authorize?response_type=token&client_id=<Yor clientId>&redirect_uri=http://localhost&scope=viewing_activity_read&state=<Some salt (Random string)>

@DocksDocks
Copy link

Error2
Now everything is ok, but im having this new error

@iFrez
Copy link
Author

iFrez commented May 27, 2020

Did u modify dist\include\idler.js like i describe above?

@DocksDocks
Copy link

Yes but the idler.js keeps reseting to the normal code when i run build

@juriadams
Copy link
Owner

juriadams commented May 27, 2020 via email

@whiteworthy
Copy link

got it to work, ty for the help @iFrez

@lolwutx
Copy link

lolwutx commented Dec 7, 2020

I modified config and idles.js as described above but instead of 401 error now I get 400. Could twitch api changed again?

DEBUG | Received following channels
(node:5204) UnhandledPromiseRejectionWarning: Error: Request failed with status code 400
at createError (/home/opc/twitch/fork/twitch-idle/node_modules/axios/lib/core/createError.js:16:15)
at settle (/home/opc/twitch/fork/twitch-idle/node_modules/axios/lib/core/settle.js:18:12)
at IncomingMessage.handleStreamEnd (/home/opc/twitch/fork/twitch-idle/node_modules/axios/lib/adapters/http.js:202:11)
at IncomingMessage.emit (events.js:326:22)
at endReadableNT (_stream_readable.js:1241:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
(node:5204) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 22)

@juriadams
Copy link
Owner

Hey guys, thought I'd update you on this.

I was/am thinking about rewriting this project to work with the Twitch channel points. This project was started when channel points weren't a thing yet and it does not work to farm channel points.

Getting this to work with channel points would require some more investigation on how they work exactly, but after looking into it a while ago, I came to the conclusion that you can only farm channel points in one stream at a time (or at least get chests in one stream at a time).

I may update this project in the future if there are enough requests.

@juriadams juriadams added enhancement New feature or request help wanted Extra attention is needed labels Dec 7, 2020
@juriadams
Copy link
Owner

Marking this as "help wanted" if someone of you guys wants to do some more in-depth investigations on how channel points work. We could maybe even implement some automatic predictions and stuff.

@iFrez
Copy link
Author

iFrez commented Dec 7, 2020

@4Dams channel points uses combination of WebSocket and OpenGraph API. Example request:
curl -H 'Host: gql.twitch.tv' -H 'Client-Id: <<User ID>>' -H 'X-Device-Id: << ???? >>' -H 'Authorization: OAuth << Auth Token >>' -H 'Content-Type: text/plain;charset=UTF-8' -H 'Origin: https://www.twitch.tv' --data-binary '[{"operationName":"ClaimCommunityPoints","variables":{"input":{"channelID":"<< Channel ID>>","claimID":"<< ID from WebSocket >>"}},"extensions":{"persistedQuery":{"version":1,"sha256Hash":"<< Request sign?? >>"}}}]' --compressed 'https://gql.twitch.tv/gql'

@PureFallen
Copy link

PureFallen commented Mar 2, 2021

Yes but the idler.js keeps reseting to the normal code when i run build

Not sure how recent that is but: idler.js gets rebuild when you use run build. The right approach would be to either start the script directly (without rebuilding each time), or to apply the changes that @iFrez mentioned in the TypeScript File that seems to be used to build idler.js.

The file should be .../twitch-idle/include/idler.ts. However, when inserting the changes, be careful with the differences between TypeScript and JavaScript:

 function Idler() {
private clientId: string = config.clientId;
private userName: string = config.userName;
private userAuth: string = config.userAuth;
private Token: string = config.token;
...
}

If you change the .ts file, you should get away running npm run build each time you want to start the program. There is probably a better solution, too.

Edit: Just realised that iFrez has a work with the exact changes required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

6 participants