YouTube.js
YouTube.js copied to clipboard
v2 Cookie authentication not working
Steps to reproduce
// Latest version from GitHub
import Innertube from 'youtubei.js';
(async () => {
const youtube = await new Innertube({
cookie: '<cookie from any request sent >'
});
console.log((await youtube.account.getInfo()).name);
})();
Failure Logs
Error: Request to /account/accounts_list failed with status code 401
at null.<anonymous> (/Users/basil/Documents/Programming/raycast/playlist-manager/node_modules/youtubei.js/build/node.js:9:250)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at Fc.account (/Users/basil/Documents/Programming/raycast/playlist-manager/node_modules/youtubei.js/build/node.js:4:2581)
at ta.getInfo (/Users/basil/Documents/Programming/raycast/playlist-manager/node_modules/youtubei.js/build/node.js:6:8961)
at null.<anonymous> (/Users/basil/Documents/Programming/raycast/playlist-manager/test.ts:10:15) {
info: {
success: false,
status_code: 401,
data: {
error: {
code: 401,
message: 'Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.',
errors: [
{
message: 'Login Required.',
domain: 'global',
reason: 'required',
location: 'Authorization',
locationType: 'header'
}
],
status: 'UNAUTHENTICATED',
details: [
{
'@type': 'type.googleapis.com/google.rpc.ErrorInfo',
reason: 'CREDENTIALS_MISSING',
domain: 'googleapis.com',
metadata: [Object]
}
]
}
}
},
date: 2022-07-13T08:46:47.811Z,
version: '2.0.0'
}
Node.js v17.8.0
Expected behavior
Requests that need authentication properly access the proper information.
Current behavior
Requests that need authentication throw an error on v2, but work on v1.
Version
Edge
Anything else?
It's only an issue on v2, cookie authentication works on v1.4.3.
I poked around, and the issue seems to stem from the base URL being switched from a the www.youtube.com
domain to one on a subdomain of googleapis.com
.
Checklist
- [X] I am running the latest version.
- [X] I checked the documentation and found no answer.
- [X] I have searched the existing issues and made sure this is not a duplicate.
- [X] I have provided sufficient information.