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

Request to https://www.youtube.com/youtubei/v1/player?prettyPrint=false&alt=json failed with status 400 #803

Open
CasandraRos opened this issue Nov 15, 2024 · 23 comments

Comments

@CasandraRos
Copy link

How to fix this error?

Error: InnertubeError: Request to https://www.youtube.com/youtubei/v1/player?prettyPrint=false&alt=json failed with status 400
at HTTPClient.fetch (/home/ubuntu/scrape/node_modules/youtubei.js/bundle/node.cjs:2074:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Actions.execute (/home/ubuntu/scrape/node_modules/youtubei.js/bundle/node.cjs:24255:22) at async Innertube.getBasicInfo (/home/ubuntu/scrape/node_modules/youtubei.js/bundle/node.cjs:29778:22)
at async Innertube.download (/home/ubuntu/scrape/node_modules/youtubei.js/bundle/node.cjs:29988:18)
at async /home/ubuntu/scrape/ytm4.js:61:20 {
info: '{\n' +
' "error": {\n' +
' "code": 400,\n' +
' "message": "Request contains an invalid argument.",\n' +
' "errors": [\n' +
' {\n' +
' "message": "Request contains an invalid argument.",\n' +
' "domain": "global",\n' +
' "reason": "badRequest"\n' +
' }\n' +
' ],\n' +
' "status": "INVALID_ARGUMENT"\n' +
' }\n' +
'}\n',
date: 2024-11-15T09:16:23.932Z,
version: '11.0.1'

@yestoall
Copy link

it was working since yesterday

@CasandraRos
Copy link
Author

it was working since yesterday

Yesterday it was still running, only recently did it start to have such an error.

@leamarty
Copy link

Same thing here, we started encountering this error around 24 hours ago. It was working fine before that.

@patrickkfkan
Copy link
Contributor

I believe this issue is the same as yt-dlp/yt-dlp#11462

If YouTube is limiting the current OAuth sign-in to just the TV client, then I suppose we'd have to return to passing cookies. I hope I'm wrong - the OAuth method is really convenient for users.

@babli118
Copy link

started getting the same error today aswell

@LArroyoS
Copy link

I believe this issue is the same as yt-dlp/yt-dlp#11462

If YouTube is limiting the current OAuth sign-in to just the TV client, then I suppose we'd have to return to passing cookies. I hope I'm wrong - the OAuth method is really convenient for users.

Hello, good day,

I think the same, we should each implement a personalized OAuth authentication or, as you mentioned, use cookies.

I don't have experience with cookies, so I would appreciate it if you could provide me with an example of how to obtain those session cookies and use them for authentication.

@LArroyoS
Copy link

I believe this issue is the same as yt-dlp/yt-dlp#11462
If YouTube is limiting the current OAuth sign-in to just the TV client, then I suppose we'd have to return to passing cookies. I hope I'm wrong - the OAuth method is really convenient for users.

Hello, good day,

I think the same, we should each implement a personalized OAuth authentication or, as you mentioned, use cookies.

I don't have experience with cookies, so I would appreciate it if you could provide me with an example of how to obtain those session cookies and use them for authentication.

I have already tried using a custom OAuth, and for now, it seems to solve this error.

However, it might be necessary to learn how to use cookies if we want to perform operations without YouTube's consumption limits.

@tonykx
Copy link

tonykx commented Nov 15, 2024

Como coloca esse OAuth personalizado, tem exemplo de código?

@LArroyoS
Copy link

Como coloca esse OAuth personalizado, tem exemplo de código?

Yes, there is an example in the official YouTube.js documentation. I basically copied and pasted it to test if it would work.

Here is the link: https://github.com/LuanRT/YouTube.js/blob/main/examples/auth/custom-oauth2-creds/index.ts

@patrickkfkan
Copy link
Contributor

I have written a guide on how to get the cookie value.

So, after getting the value, you pass it like this:

const innertube = await Innertube.create({  cookie });

I have already tried using a custom OAuth, and for now, it seems to solve this error.

Interesting. Appreciate if you could share the process too?

@LArroyoS
Copy link

He escrito una guía sobre cómo obtener el valor de la cookie.

Entonces, después de obtener el valor, lo pasa así:

What might be a bit complicated is obtaining the OAuth credentials.

  • To do this, you need to create a new project.
  • Go to APIs and services.
  • Configure the OAuth consent screen.
  • Then go to credentials and create a new credential 'OAuth client ID'.
  • Select the type of application, in my case, since I have it locally, I use "Desktop app", as the others have restrictions for using http://localhost:.
  • When you create the credential, copy the client ID and the key.

This video can guide you, it's not about OAuth, but the steps are the same, you just need to choose 'OAuth ID' in credentials.

https://www.youtube.com/watch?time_continue=76&v=LLAZUTbc97I&embeds_referring_euri=https%3A%2F%2Fwww.bing.com%2F&embeds_referring_origin=https%3A%2F%2Fwww.bing.com&source_ve_path=Mjg2NjY

@tonykx
Copy link

tonykx commented Nov 15, 2024

Será que vai ter uma atualização na biblioteca que resolva, ou precisamos mexer no código?

@LArroyoS
Copy link

¿Habrá una actualización de la biblioteca que lo resuelva, o necesitamos cambiar el código?

No, I know, but I recommend starting to learn about these settings.

@patrickkfkan
Copy link
Contributor

Custom OAuth could be an effective solution too. I remember creating a few for use with the official YouTube API a couple years back. Then came this project that made everything so much more simple and powerful 😍

@tonykx
Copy link

tonykx commented Nov 15, 2024

O OAuth personalizado também pode ser uma solução eficaz. Lembro-me de criar alguns para usar com a API oficial do YouTube alguns anos atrás. Então veio esse projeto que tornou tudo muito mais simples e poderoso 😍

Envie seu código aqui pra eu ver como devo fazer

@LArroyoS
Copy link

I have written a guide on how to get the cookie value.

So, after getting the value, you pass it like this:

const innertube = await Innertube.create({  cookie });

I have already tried using a custom OAuth, and for now, it seems to solve this error.

Interesting. Appreciate if you could share the process too?

I have written a guide on how to get the cookie value.

So, after getting the value, you pass it like this:

const innertube = await Innertube.create({  cookie });

I have already tried using a custom OAuth, and for now, it seems to solve this error.

Interesting. Appreciate if you could share the process too?

I am going to opt for using cookies. I have conducted some tests as you indicated, and I must say it works. However, I have a question: how can I obtain data from a specific channel?

For instance, I have two channels on my YouTube account, the main one and a secondary one. By passing the cookies, I only get data from my main user, but I want to access my secondary channel.

Is there any way to do this using cookies?

@tonykx
Copy link

tonykx commented Nov 16, 2024

Can any of you tell what is missing in my function, I tried using cookies:

case 'play2': {
if (args.length < 1) return reply("Insira o comando, e em seguida um nome para a pesquisa!");

const { Innertube } = require('youtubei.js');
const fetch = (await import("node-fetch")).default;
const fs = require('fs');

// Criação da instância do Innertube com cookies
const cookie = 'z'; // Substitua pelo cookie adequado
const youtube = await Innertube.create({ cookie });

try {
    // Realiza a pesquisa diretamente
    const searchResults = await youtube.search(args.join(" "));
    const firstResult = searchResults.results[0];
    
    if (!firstResult) {
        return reply("Nenhum vídeo encontrado.");
    }

    const videoId = firstResult.id;
    const videoInfo = await youtube.getBasicInfo(videoId);
    const audioFormat = videoInfo.streaming_data?.formats[0]; 
    
    if (!audioFormat) {
        return reply("Formato de áudio não encontrado.");
    }

    const audioUrl = audioFormat.decipher(youtube.session.player);
    const vidName = `audio_${Date.now()}.mp3`;
    const path = `Del/${vidName}`;
    const writer = fs.createWriteStream(path);

    const audioStream = await fetch(audioUrl);
    
    if (!audioStream.ok) {
        throw new Error(`Erro ao baixar áudio: ${audioStream.statusText}`);
    }
    
    audioStream.body.pipe(writer);

    writer.on("finish", async () => {
        console.log("Download Completo!");
        await conn.sendMessage(from, { audio: { url: path }, mimetype: "audio/mpeg" }, { quoted: info });
        fs.unlink(path, (err) => {
            if (err) console.error("Erro ao deletar o arquivo:", err);
        });
    });

} catch (error) {
    console.error("Erro durante o processo:", error);
    reply("Ocorreu um erro ao tentar reproduzir o áudio.");
}

break;

}

@tonykx
Copy link

tonykx commented Nov 16, 2024

The error says the audio format was not found

@CasandraRos
Copy link
Author

CasandraRos commented Nov 16, 2024

I have written a guide on how to get the cookie value.
So, after getting the value, you pass it like this:

const innertube = await Innertube.create({  cookie });

I have already tried using a custom OAuth, and for now, it seems to solve this error.

Interesting. Appreciate if you could share the process too?

I have written a guide on how to get the cookie value.
So, after getting the value, you pass it like this:

const innertube = await Innertube.create({  cookie });

I have already tried using a custom OAuth, and for now, it seems to solve this error.

Interesting. Appreciate if you could share the process too?

I am going to opt for using cookies. I have conducted some tests as you indicated, and I must say it works. However, I have a question: how can I obtain data from a specific channel?

For instance, I have two channels on my YouTube account, the main one and a secondary one. By passing the cookies, I only get data from my main user, but I want to access my secondary channel.

Is there any way to do this using cookies?

How do I use cookies?, I used cookies before but I have to change my cookies frequently, is there a way to solve that?

@sgebr01
Copy link

sgebr01 commented Nov 17, 2024

@LArroyoS Does that not require google to approve you?

@farhaanaliii
Copy link

I am getting the same error :(

@LArroyoS
Copy link

@LArroyoS Does that not require google to approve you?

No, you do not need YouTube to approve your app unless you need to store more than 100 users.

@farhaanaliii
Copy link

Como coloca esse OAuth personalizado, tem exemplo de código?

Yes, there is an example in the official YouTube.js documentation. I basically copied and pasted it to test if it would work.

Here is the link: https://github.com/LuanRT/YouTube.js/blob/main/examples/auth/custom-oauth2-creds/index.ts

Thanks! This method worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants