youtube-viewer icon indicating copy to clipboard operation
youtube-viewer copied to clipboard

Default API key is disabled

Open trizen opened this issue 4 years ago • 41 comments

I recently got the following message from the YouTube API Services team:

Dear YouTube API Developer,

For your use of YouTube API Services, we have sent multiple reminders, which required you to submit a completed Audit Form with (i) fully-functional demo accounts, (ii) screenshots and (iii) documents in relation to your API Client. As a result we have reduced your quota access to YouTube Data API.

You have three (3) days to respond to this message with the requested information, failing which access to YouTube Data API would be affected.

Thanks,

YouTube API Services team

They reduced the quota limit from 25M to 12.5M queries per day: 2020-02-25-105627_1920x1080_scrot

Everyone is requested to create their own API key and client ID/SECRET values, otherwise youtube-viewer will no longer work.

Check the instructions in README.md for how to create your own API key.

Edit: the default API key of youtube-viewer is now disabled.

trizen avatar Feb 25 '20 09:02 trizen

This would also be a good time to get in touch with distribution package maintainers. Distributions that have a nonprofit API account with Google may be able to include distribution-specific keys with their packaged versions.

I'm the Arch maintainer, and we're not yet set up for that, but I believe someone's working on it for unrelated reasons.

escondida avatar Feb 25 '20 19:02 escondida

If a distribution wants to package youtube-viewer with an API key, I can modify the program to read the default values from /etc/youtube-viewer/api.json (if this file exists).

Then, if an user chooses to use their own API key, they can specify it in ~/.config/youtube-viewer/api.json.

Edit 1: as an alternative to using an YouTube API key, I created a fork of youtube-viewer, called straw-viewer, which uses the API of invidio.us to search for YouTube videos. The project is in its early stages of development and it may lack some features, but, for basic stuff, like searching for videos and playlists, it should work without many issues.

Edit 2: another alternative is pipe-viewer, which parses the YouTube website directly in a similar way like NewPipe does.

trizen avatar Feb 25 '20 20:02 trizen

Then, if an user chooses to use their own API key, they can specify it in ~/.config/youtube-viewer/api.json.

How should that .json file look? I have one from kodi's youtube addon named api_keys.json. It looks like this and it contains the api keys I had made for myself a few days ago when google started all that bs

{
    "keys": {
        "developer": {}, 
        "personal": {
            "api_key": "xxx", 
            "client_id": "xxx", 
            "client_secret": "xxx"
        }
    }
}

Will youtube-viewer work if I just copy it over to the forementioned folder and rename it?

---edit Nope. I just tried it and it did not work. It pops the exact same error I mentioned earluer today on #303

pitsi avatar Feb 26 '20 13:02 pitsi

The format of ~/.config/youtube-viewer/api.json is:

{
    "key":           "API_KEY",
    "client_id":     "CLIENT_ID",
    "client_secret": "CLIENT_SECRET"
}

See: https://github.com/trizen/youtube-viewer#logging-in

trizen avatar Feb 26 '20 13:02 trizen

Still no go. This is how it looks now

{
        "key": "xxx",
        "client_id": "xxx",
        "client_secret": "xxx"
}

And the error remains the same. I have to leave for work now, I will look it up when I get home. Getting the api keys from google and inserting them properly on the addon was a real pita, that is why I copied the file over as I did for all my devices that run kodi.

pitsi avatar Feb 26 '20 13:02 pitsi

it needs 5/10 mins to propogate to the gogle servers

cirrusUK avatar Feb 26 '20 13:02 cirrusUK

If you're logged in using the previous credentials, try youtube-viewer --logout.

trizen avatar Feb 26 '20 13:02 trizen

It's nothing much that I can do about it...

If a distribution wants to package youtube-viewer with an API key, I can modify the program to read the default values from /etc/youtube-viewer/api.json (if this file exists).

Then, if an user chooses to use their own API key, they can specify it in ~/.config/youtube-viewer/api.json.

By the way, mps-youtube is also affected: mps-youtube/mps-youtube#1063 Additionally, something somewhat funny: https://stackoverflow.com/a/60264537

Edit: as an alternative to using an YouTube API key, I created a fork of youtube-viewer, called straw-viewer, which uses the API of invidio.us to search for YouTube videos. The project is in its early stages of development and it may lack some features, but, for basic stuff, like searching for videos and playlists, it should work without many issues.

doesn't youtube-viewer already have invidious support, with the "--invidious!" command? Also the title itself is misleading: unless Google restricts people making API keys, we can just create our own API key for youtube-viewer/mpsyt and use that.

Jack-O-Brian avatar Feb 26 '20 18:02 Jack-O-Brian

Do I also need to tell youtube-viewer about my youtube account, or is creating the api.json file sufficient?

rien333 avatar Feb 26 '20 18:02 rien333

@HawaiinPizza: doesn't youtube-viewer already have invidious support, with the "--invidious!" command?

Not really. The API of invidio.us is used only in extracting the streaming URLs for some videos.

@rien333: Do I also need to tell youtube-viewer about my youtube account, or is creating the api.json file sufficient?

Specifying the API key in api.json should be sufficient. The client ID/SECRET values are optional and they are used only for logging in.

trizen avatar Feb 26 '20 18:02 trizen

EDIT: This is my fault. I was signed and forgot, but once I signed out I fixed the problem.

In light of having to use personal API key, I changed my API to the one I use for mpsyt, and for mpsyt it works. However, for youtube-viewer, it doesn't. I use the same key for mpsyt, I remove the client_id and client_secret thinking maybe they caused it, they didn't change anything. I made my own client_id and client_secret and put it in, and it didn't work.

The error message I'm getting is

** GET https://www.googleapis.com/youtube/v3/search?key=(KEY)&maxResults=20&part=snippet&prettyPrint=false&q=wow&type=video ==> 500 Internal Server Error (1s)
** GET https://www.googleapis.com/youtube/v3/search?key=(KEY)&maxResults=20&part=snippet&prettyPrint=false&q=wow&type=video ==> 500 Internal Server Error
** GET https://www.googleapis.com/youtube/v3/search?key=(KEY)&maxResults=20&part=snippet&prettyPrint=false&q=wow&type=video ==> 500 Internal Server Error
** GET https://www.googleapis.com/youtube/v3/search?key=(KEY)&maxResults=20&part=snippet&prettyPrint=false&q=wow&type=video ==> 500 Internal Server Error
** GET https://www.googleapis.com/youtube/v3/search?key=(KEY)&maxResults=20&part=snippet&prettyPrint=false&q=wow&type=video ==> 500 Internal Server Error
[500 Internal Server Error] Error occurred on URL: https://www.googleapis.com/youtube/v3/search?key=[...]&maxResults=20&part=snippet&prettyPrint=false&q=wow&type=video
Use of uninitialized value in numeric gt (>) at /usr/share/perl5/vendor_perl/WWW/YoutubeViewer/Utils.pm line 224.

I copied the url it mention [the (KEY) part was my API key] and it works.

I tried looking into Utils.pm, and at line 224, it's this code

sub has_entries {
    my ($self, $result) = @_;
    ref($result) eq 'HASH' and ($result->{results}{pageInfo}{totalResults} > 0);
}

I removed the and statment, but it didn't do anything, only removed the "Use of uninitialized value in numeric gt" error message

I am using YouTube Viewer 3.7.4 on Arch Linux, using the latest youtube-viewer package.

Jack-O-Brian avatar Feb 26 '20 19:02 Jack-O-Brian

it needs 5/10 mins to propogate to the gogle servers

I logged in on my pc via ssh and tried it again 1+ hour after making the post above, but the error was the same.

If you're logged in using the previous credentials, try youtube-viewer --logout.

I do not use credentials on any app that plays content from youtube. I tried it though, but the result was the same.

Just to be sure, the api.json function is availabe to youtube viewer 3.7.4 only, right? Because that is what I have. If not, I will have to clone the git repo and try the git version, obviously because it is newer. Bottom line, I am really fed up with google's bs, because I had similar issues while I was importing my keys to kodi's addon too. I may give straw-viewer a shot later on.

---edit Just as I asked for the kodi addon, can someone inform me about the form of the keys? For me they are as follows

  • api key = a string of 39 characters, containing numbers and letters, upper and lowercase
  • cliend id = a string of 45 charactes as above, that starts with 12 characters which are numbers only, then a dash and then 32 characters as above
  • client key = a string of 24 characters as above, that starts with 12 characters, then a dash and then 11 characters

Are yours similar?

pitsi avatar Feb 27 '20 06:02 pitsi

Just to be sure, the api.json function is available to youtube viewer 3.7.4 only, right?

Yes. That is correct.

  • The API key starts with AIza... (39 characters long).
  • The client ID has the form: xxx.apps.googleusercontent.com
  • The client SECRET is a string of 24 random characters.

trizen avatar Feb 27 '20 06:02 trizen

The API key starts with AIza... (39 characters long).

Check!

The client ID has the form: xxx.apps.googleusercontent.com

Do I also need the ".apps.googleusercontent.com" part? The kodi addon automatically chops it off, so it was not in the file when it was copied.

The client SECRET is a string of 24 random characters.

Check!

Thank you :)

pitsi avatar Feb 27 '20 08:02 pitsi

Try:

youtube-viewer --debug test

It should print an URL with the API key included. Check to see if it actually uses the correct key.

Optionally, copy-paste the URL into a browser to see if if that works and if there are any error messages.

trizen avatar Feb 27 '20 09:02 trizen

I am an idiot :( I had left an extra bracket ( "{" ) inside the file and it was messing things up. I fixed it now and it is working as it should. Sorry for all the hussle guys. Thank you for pointing out the --debug switch. I was able to check the api key with it when youtube-viewer runs and found out that it used AIza..22Q which is youtube-viewer's default, instead of mine which is AIza...GR4.

pitsi avatar Feb 27 '20 11:02 pitsi

so paste some keys...

clort81 avatar Feb 28 '20 05:02 clort81

Not sure whether that's gonna help.

I used yt-viewer w/ a very old gentoo key which worked for about a day (and maybe half a dozen searches), but 403's since yesterday evening CET. I then tried the key arch uses for chromium. 403's as well (w/ and w/o ID and secret)

The little paranoid guy in the back of my head thinks they're shutting down API access to enforce using the browser which is, given of the awesome HW acceleration support in linux browsers, nice /sarcasm

yt-dl still works, so you can play a URL w/ eg. mpv.

luebking avatar Feb 28 '20 07:02 luebking

Update: the key works again. Either google is fiddling around or this is due to severly capped quotas in which case you'll need a private key.

luebking avatar Feb 28 '20 13:02 luebking

@clort81 The keys are pesonal and linked to my google account, so I won't share them.

@luebking I can't confirm that. Removing api.json makes the 403 error come up again. And the same happens on kodi's youtube addon. And how did you get the keys from those distros? Debian had something similar for its chromium in /etc/chromium.d/apikeys. I tried them in kodi's addon, but they did not work.

pitsi avatar Feb 28 '20 14:02 pitsi

Chromium PKGBUILD and the gentoo key was in some post, 5 years ago or so. As mentioned, it meanwhile works again, so I guess this is a quota thing (and was exceeded last night)

luebking avatar Feb 28 '20 15:02 luebking

Can't make it work because youtube-viewer keeps using the default API key. I have generated API keys and put them to ~/.config/youtube-viewer/api.json

~$ cat ~/.config/youtube-viewer/api.json { "key": "***ftQ", "client_id": "****", "client_secret": "****" }

Here is the debug output:

> youtube-viewer --debug test
** GET https://www.googleapis.com/youtube/v3/search?key=AIzaSyA2PQakgMYbX3U3imqplLMhpfM8mzEn22Q&maxResults=20&part=snippet&prettyPrint=false&q=youtube-viewer%20test&type=video ==> 403 Forbidden (1s)
[403 Forbidden] Error occured on URL: https://www.googleapis.com/youtube/v3/search?key=AIzaSyA2PQakgMYbX3U3imqplLMhpfM8mzEn22Q&maxResults=20&part=snippet&prettyPrint=false&q=youtube-viewer%20test&type=video

Notice it keeps using 22Q instead of my key ftQ. I've tried youtube-viewer --logout and launching youtube-viewer in a new terminal window. My distro is Elementary OS Juno (5.0)

kubk avatar Feb 29 '20 11:02 kubk

Make sure to have the latest version of youtube-viewer installed (3.7.4).

trizen avatar Feb 29 '20 11:02 trizen

I have my Youtube Data API key specified in .config/youtube-viewer/api.json, but I'm still getting a 403 errorr. youtube-viewer --debug test throws
** GET https://www.googleapis.com/youtube/v3/search?key=AIzaSyMyKeySRM&maxResults=20&part=snippet&prettyPrint=false&q=test&type=video ==> 403 Forbidden (1s) [403 Forbidden] Error occurred on URL: https://www.googleapis.com/youtube/v3/search?key=[...]&maxResults=20&part=snippet&prettyPrint=false&q=test&type=video Use of uninitialized value in numeric gt (>) at /usr/share/perl5/vendor_perl/WWW/YoutubeViewer/Utils.pm line 224.

When I copy that URL into Firefox, I get
"message": "Access Not Configured. YouTube Data API has not been used in project 171421846572 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/youtube.googleapis.com/overview?project=MyProjectName then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry."

The API is enabled and has been for a few months. Afaik it worked with mps-youtube or a similar youtube program when I made the key.

mcz avatar Feb 29 '20 18:02 mcz

Try to create a new project with a new API key. Apparently, Google automatically disables the API keys that have not been used for 90 consecutive days.

See: https://stackoverflow.com/questions/55620912/youtube-may-disable-your-inactive-projects-access-to-the-youtube-data-api-servi

trizen avatar Mar 01 '20 05:03 trizen

So all that means, if i want to use it i will be tracked by google again ?

asteriosos avatar Mar 01 '20 08:03 asteriosos

@asteriosos: Sadly, yes. As an alternative, I created straw-viewer, which uses the API of invidio.us, and thus it does not require an YouTube API key.

trizen avatar Mar 01 '20 08:03 trizen

I have the following issue with my keys and I would like to ask if anyone else has it too.

I have made my personal keys and I use them on youtube-viewer and on kodi's youtube addon. That is... 4 devices in total, youtube-viewer on my pc and the kodi addon on the pc, an old laptop and an rpi3b+. In general, I have zero issues during the day and every search works as it should with no 403 errors. But sometimes, that 403 error comes up when I least expect it too and it happens only on mornings (6.30am to 8.30am). The api resets the counter daily at 12pm pacific time, which is 10am for me here on gmt+2. I make a search on the kodi addon and I get a 403. Then I make another one on youtube viewer and it works. Once the playback is over, I make another one and I get the 403. What is even more weird, sometimes I search for something, e.g. song A, and I get the 403 error. I search again the very next second for e.g. song B and there is no error, just results that play! And it happens on both youtube-viewer and kodi's addon.

Does it only happen to me, or is the new api somewhat garbage? I have checked the "stats" table on my google account and the bars are merely visible.

Irrelevant to the above, but I have access to a google account that can not be deleted (info upon request). Do you want me to use it and make a set of keys for youtube-viewer?

pitsi avatar Mar 20 '20 12:03 pitsi

It may be promised the "Incognito" mode feature implementation. Of course, it's a piece of work, you can't use API tokens and needs reverse engineering of browser flow. But it'll be player with keeping privacy.

animant avatar Apr 04 '20 18:04 animant

One more thing that proves, at least for me, that the new api is garbage. I am following the usual routine I described above, like on every other morning. Earlier, I tried to play this list here youtube-viewer -s --pp=PLPl862cpmLY68gNTNA8irOPNNo9jf8wAL

And from all 12 songs, only 5, 6, 7 and 10 played and all the others were just skipped with a 403 error.

Everything starts as it should, with the descrtiption at the top

=> Description
------------------------------------------------------------------------------------------------------------------
blablabla

then the actual url of the video and its info

------------------------------------------------------------------------------------------------------------------
=> URL: https://www.youtube.com/watch?v=Jy3bsT2kH-k
------------------------------------------------------------------------------------------------------------------
                                          =>> Anser x Eversor - ΚΙΧ <<=

-> Channel   : Anser
-> ChannelID : UCtlJcPWvqTQjgAzkmaUykCg
-> VideoID   : Jy3bsT2kH-k
blablabla
------------------------------------------------------------------------------------------------------------------

And yet nothing plays! Doing the same with the --debug option gives similar results It plays a different set of videos but it pops the usual 403 error on the ones that do not play, so I now definitely know the reason why they do not play.

What is even worse is that if I try to open a video on mpv, which simply uses youtube-dl to parse the urls and play them, the 403 error comes up again! I do have my own api keys, but how the f am supposed to make mpv use them?

Youtube-viewer 3.7.5, mpv 0.32, youtube-dl 2020.03.24. Every video that got skipped with the 403 error plays at it should in the web browser.

pitsi avatar Apr 18 '20 06:04 pitsi