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

Invalid value "undefined" for header "X-Goog-Visitor-Id" #30

Open
ArakJamman opened this issue Aug 31, 2022 · 5 comments
Open

Invalid value "undefined" for header "X-Goog-Visitor-Id" #30

ArakJamman opened this issue Aug 31, 2022 · 5 comments

Comments

@ArakJamman
Copy link

This is a very useful package, but I am having some problems when searching with the api. It seems like this issue was opened and closed in b52b2b0, but I am still having this issue...

  • When I use the api like so, the search is successful:
    image

  • However, when I use the api like this, the search is unsuccessful:
    image
    image

Any fixes for this? Thanks...

@TPausL
Copy link

TPausL commented Sep 20, 2022

i guess b52b2b0 wasn't published on npm
could @emresenyuva, @wilsonpage or @valeriangalliat do that?

@RamalS
Copy link

RamalS commented Oct 13, 2022

@ArakJamman @mcitomiapplecat I had the same problem. For now, go to node_modules/youtube-music-api/src/index.js and replace line 49 with 'X-Goog-Visitor-Id': this.ytcfg.VISITOR_DATA || ''.
image

@lorenzo132 lorenzo132 mentioned this issue Oct 23, 2022
@abetwothree
Copy link

The issues looks to be that you need to wait for api.initialize to finish it's HTTP request. Initialize actually pings YouTube music to grab session cookies in order to be able to ping the private API so you can't make any API requests until initialize finishes grabbing session cookies.

Recommend using async/await pattern so you can do this:

await api.initizalize();
const result = await api.search('search term', 'song', 1);

I created a small REST api app for this package where you can see me doing the async/await stuff.
https://github.com/abetwothree/youtube-music-rest-api-microservice

@pigiax
Copy link

pigiax commented Mar 9, 2023

Hi, there is a workaround if you are not able to make it work:

const YouTubeMusicAPI = require('youtube-music-api');

const youtubeMusic = new YouTubeMusicAPI();

async function searchForSong(title, artist) {
    await youtubeMusic.initalize();
    youtubeMusic.ytcfg.VISITOR_DATA = '';
    const searchResult = await youtubeMusic.search(`${title} ${artist}`);
    if (searchResult && searchResult.content) {
        const songId = searchResult.content[0].videoId;
        const songUrl = `https://www.youtube.com/watch?v=${songId}`;
        console.log(songUrl);
        return songUrl;
    }
    return null;
}

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

6 participants
@abetwothree @pigiax @RamalS @TPausL @ArakJamman and others