LuanRT / YouTube.js

A JavaScript client for YouTube's private API, known as InnerTube.
https://ytjs.dev
MIT License
3.54k stars 224 forks source link

2.3.2 Upload failed with status 401 #227

Open flolep2607 opened 1 year ago

flolep2607 commented 1 year ago

Steps to reproduce

It's not a brand account

Failure Logs

Hello!
On your phone or computer, go to https://www.google.com/device and enter the code ZRV-QTD-DGP
Successfully signed in!
/home/flo/mass_prox/tst/node_modules/youtubei.js/dist/src/utils/HTTPClient.js:112
            throw new Utils_1.InnertubeError(`Request to ${response.url} failed with status ${response.status}`, yield response.text());
                  ^

InnertubeError: Request to https://upload.youtube.com//upload/youtubei?key=xxxxxxxxxxxxxxxxxxxx&prettyPrint=false&alt=json failed with status 401
    at HTTPClient.<anonymous> (/home/flo/mass_prox/tst/node_modules/youtubei.js/dist/src/utils/HTTPClient.js:112:19)
    at Generator.next (<anonymous>)
    at fulfilled (/home/flo/mass_prox/tst/node_modules/youtubei.js/dist/src/utils/HTTPClient.js:5:58)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  info: '{"status":"STATUS_REJECTED","rejectionReason":"REJECTED_NOT_AUTHENTICATED"}',
  date: 2022-11-05T16:02:11.243Z,
  version: '2.3.2'
}

Node.js v17.9.1

Expected behavior

upload the video

Current behavior

response code 401 unable to upload

Version

Default

Anything else?

It's not a brand account

Checklist

LuanRT commented 1 year ago

Hmm weird, are you able to update video metadata? I've never seen this happening with normal accounts.

bezaleel22 commented 1 year ago

i'm also getting this, any update?

LuanRT commented 1 year ago

i'm also getting this, any update?

@onos9 Are you able to use other methods that require authentication (update video thumbnail, metadata, get account info and etc)? I tried reproducing this but unfortunately couldn't, so it's a bit complicated to debug. You can also try cookie auth to see if it throws the same error.

Edit: And if possible, please try uploading with different accounts.

bezaleel22 commented 1 year ago

Thanks for the feedback, I have not really tried other methods, I'm actually new to this repository, what do I need to do get credentials for login. I used Google Oauth2 and also realised there is no option for youtube-private-video and gdata in the consent scope. Thanks for this great project, I would really love to use this in my project, thanks.

bezaleel22 commented 1 year ago

I have successfully uploaded a video, thank you very much for your response, is there any callback for upload progress?

bezaleel22 commented 1 year ago

@LuanRT is there any documentation on how to login via cookie specifically what cookie name copy from the cookie store

yashb042 commented 1 year ago

@onos9 Were you able to successfully upload a video using this library? I can't seem to find a way to upload. New to this library.

LuanRT commented 1 year ago

@onos9 Were you able to successfully upload a video using this library? I can't seem to find a way to upload. New to this library.

@yashb042 Can you try cookie authentication? Just copy the whole cookie from a YouTube's API req and pass it to the cookieoption in the library.

I'm still trying to figure out why this happens to some accounts, but I reckon it's most likely because the /upload/youtubei endpoint is rejecting the OAuth bearer token.

Edit: If you're just looking for examples, there's one here.

bezaleel22 commented 1 year ago

@yashb042 yes I was able to upload successful, it actually worked for my account

bezaleel22 commented 1 year ago

@LuanRT just curious, is there a way to live stream from this library if so, can you show an example.

A live streaming feature will be awesome for this great library. Thanks for the work it really help me alot.

LuanRT commented 1 year ago

@onos9

Not possible yet.

The way YouTube handles live streams seems a bit complicated, but I do want to try to implement it at some point.

Thanks!

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

gunpal5 commented 1 year ago

Hello,

I am also getting this problem. I think 401 problem comes with newly created Channel on Youtube.

So, Step to reproduce the error would be:

1) Create New YouTube channel and don't verify the phone number. 2) try to upload video to new channel with Youtube.js and it will start to give 401 error.

Successfully signed in! { 'Content-Type': 'application/x-www-form-urlencoded', 'x-goog-upload-command': 'start', 'x-goog-upload-protocol': 'resumable' } URL { href: 'https://upload.youtube.com//upload/youtubei?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8&prettyPrint=false&alt=json', origin: 'https://upload.youtube.com', protocol: 'https:', username: '', password: '', host: 'upload.youtube.com', hostname: 'upload.youtube.com', port: '', pathname: '//upload/youtubei', search: '?key=AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8&prettyPrint=false&alt=json', searchParams: URLSearchParams { 'key' => 'AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8', 'prettyPrint' => 'false', 'alt' => 'json' }, hash: '' } InnertubeError: Request to https://upload.youtube.com//upload/youtubei?prettyPrint=false&alt=json failed with status 401 at HTTPClient.<anonymous> (C:\Users\Gunpa\Downloads\YouTube.js-main (1)\YouTube.js-main\examples\channel\node_modules\youtubei.js\src\utils\HTTPClient.ts:145:13) at Generator.next (<anonymous>) at fulfilled (C:\Users\Gunpa\Downloads\YouTube.js-main (1)\YouTube.js-main\examples\channel\node_modules\tslib\tslib.js:164:62) at processTicksAndRejections (node:internal/process/task_queues:95:5) { info: '{"status":"STATUS_REJECTED","rejectionReason":"REJECTED_NOT_AUTHENTICATED"}', date: 2023-04-19T18:05:51.530Z, version: '4.3.0' }

I am looking for solution to upload videos on newly created channel.

LuanRT commented 1 year ago

@gunpal5 Thank you! That seems to be the case indeed. I'm not very hopeful but I'll see if there's any workaround.

gunpal5 commented 1 year ago

@LuanRT

I have C# codes which uploads to YouTube just fine on newly created channel. but those codes require YouTube cookies to work, these cookies are the same when you login to Youtube on a web browser like Google Chrome.

I am not sure if you have any cookies based authentication implemented in Youtube.js. If you have it I will share the codes.

The codes I have basically mimic the http calls, which are sent to YouTube server when you try to upload videos through a web browser.

Anyway, I appreciate your efforts in developing a library like YouTube.js

LuanRT commented 1 year ago

@gunpal5 Yes it does support cookies. Feel free to share anything you think might help solving this, it'd be greatly appreciated!

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

chen-rn commented 1 year ago

I seem to be running into this issue as well, and I see no option in Youtube to verify my phone number. The account is about 3 weeks old.

@LuanRT How do I use cookies with Youtubejs?

LuanRT commented 1 year ago

I seem to be running into this issue as well, and I see no option in Youtube to verify my phone number. The account is about 3 weeks old.

@LuanRT How do I use cookies with Youtubejs?

Check if you can upload from the YouTube app itself first. It should prompt you to do whatever verification is needed.

As for cookies, try the cookie prop when creating a new session.

chen-rn commented 1 year ago

I can upload from the Youtube Studio web app. I do not have an android device on me to test using the Youtube app.

I'll try the cookies method!

cantfindone commented 9 months ago

I have 4 channels under 1 acount. The first channel works perfctly, but the rest 3 encountered 401 when uploading videos.

LuanRT commented 9 months ago

@cantfindone Yeah, this is still a problem unfortunately. I'll have to investigate how the mobile app handles this to implement it properly in YouTube.js.