plugin.video.youtube icon indicating copy to clipboard operation
plugin.video.youtube copied to clipboard

Youtube API Sign in issue

Open buggerlugz opened this issue 5 years ago • 5 comments

Context

  • Add-on Version: Latest Beta 3
  • Kodi Version: Kodi v18.9 "Leia" (fresh install)
  • Kodi GUI Language: English
  • Operating System: Libreelec
  • Operating System Language: English

Expected Behavior

I have created the API key, Auth client ID and secret on google console and entered them correctly into the youtube app settings. When I click search it does return videos and plays them fine. I'd expect it to automatically sign in to my youtube account.


Current Behavior

When I click sign in, I immediately get 401 Code: 'The OAuth client was not found' , I've tried resetting the cache, access control and changed the API key but it makes no difference. Nothing allows me to sign in to youtube. The log looks a right mess.


Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. boot up kodi
  2. select youtube app
  3. click "sign in"

Log

2020-12-30 10:04:22.714 T:1741673344 NOTICE: Register - new cec device registered on cec->RPI: CEC Adapter (2708:1001) 2020-12-30 10:04:47.959 T:1544364928 ERROR: [plugin.video.youtube] Requesting device and user code failed: Code: |401| JSON: |{u'error_description': u'The OAuth client was not found.', u'error': u'invalid_client'}| 2020-12-30 10:04:47.989 T:1544364928 ERROR: [plugin.video.youtube] LoginException: [401] invalid_client: The OAuth client was not found. 2020-12-30 10:04:47.991 T:1544364928 WARNING: Attempt to use invalid handle -1 2020-12-30 10:05:25.041 T:1523577728 WARNING: CPythonInvoker(9): Script invoked without an addon. Adding all addon modules installed to python path as fallback. This behaviour will be removed in future version. 2020-12-30 10:05:28.053 T:1523577728 WARNING: CPythonInvoker(11): Script invoked without an addon. Adding all addon modules installed to python path as fallback. This behaviour will be removed in future version. 2020-12-30 10:05:51.370 T:1523577728 WARNING: [plugin.video.youtube] User: |0| Switching API key set to |own| 2020-12-30 10:05:52.558 T:1560253312 WARNING: Attempt to use invalid handle -1 2020-12-30 10:05:52.806 T:1504965504 WARNING: CPythonInvoker(16): Script invoked without an addon. Adding all addon modules installed to python path as fallback. This behaviour will be removed in future version. 2020-12-30 10:05:59.683 T:1523577728 ERROR: GetDirectory - Error getting /storage/.kodi/temp/plugin.video.youtube/ 2020-12-30 10:06:05.007 T:1523577728 WARNING: CPythonInvoker(18): Script invoked without an addon. Adding all addon modules installed to python path as fallback. This behaviour will be removed in future version. 2020-12-30 10:06:14.583 T:1937127872 ERROR: Control 55 in window 10025 has been asked to focus, but it can't 2020-12-30 10:06:40.073 T:1523577728 ERROR: Previous line repeats 1 times. 2020-12-30 10:06:40.073 T:1523577728 ERROR: [plugin.video.youtube] Requesting device and user code failed: Code: |401| JSON: |{u'error_description': u'The OAuth client was not found.', u'error': u'invalid_client'}| 2020-12-30 10:06:40.109 T:1523577728 ERROR: [plugin.video.youtube] LoginException: [401] invalid_client: The OAuth client was not found. 2020-12-30 10:06:40.111 T:1523577728 WARNING: Attempt to use invalid handle -1 2020-12-30 10:07:13.080 T:1560253312 WARNING: CPythonInvoker(22): Script invoked without an addon. Adding all addon modules installed to python path as fallback. This behaviour will be removed in future version. 2020-12-30 10:07:14.070 T:1523577728 WARNING: [plugin.video.youtube] User: |1| Switching API key set to |own| 2020-12-30 10:07:15.496 T:1544364928 WARNING: Attempt to use invalid handle -1 2020-12-30 10:07:15.696 T:1523577728 WARNING: CPythonInvoker(25): Script invoked without an addon. Adding all addon modules installed to python path as fallback. This behaviour will be removed in future version. 2020-12-30 10:12:27.244 T:1770840960 WARNING: CPythonInvoker(27): Script invoked without an addon. Adding all addon modules installed to python path as fallback. This behaviour will be removed in future version. 2020-12-30 10:12:28.294 T:1799328640 WARNING: [plugin.video.youtube] User: |1| Switching API key set to |own| 2020-12-30 10:12:29.786 T:1807721344 WARNING: Attempt to use invalid handle -1 2020-12-30 10:12:29.995 T:1544364928 WARNING: CPythonInvoker(30): Script invoked without an addon. Adding all addon modules installed to python path as fallback. This behaviour will be removed in future version. 2020-12-30 10:12:43.006 T:1807721344 ERROR: [plugin.video.youtube] Requesting device and user code failed: Code: |401| JSON: |{u'error_description': u'The OAuth client was not found.', u'error': u'invalid_client'}| 2020-12-30 10:12:43.037 T:1807721344 ERROR: [plugin.video.youtube] LoginException: [401] invalid_client: The OAuth client was not found.


buggerlugz avatar Dec 30 '20 11:12 buggerlugz

Installed the latest stable youtube build from the kodi repo and it allows me to "log in twice" but still returns the same 401 code. It appears google has altered the API recently to not allow you to call the subscription element and instead it just bails out and reports a 401 to me.

buggerlugz avatar Dec 30 '20 13:12 buggerlugz

Does anyone even monitor this group?

buggerlugz avatar Jan 01 '21 11:01 buggerlugz

Don't forget it's the holiday period for most and as such everyone is taking a much needed break. It's not an issue with the addon, but the Google has changed some things in the backend that have broken the quotas on old projects.

Create a new project like you did orignally to set it up, forget the old project as it is now invalid and won't work. Create a new set of API, Client ID and Secret, and don't forget to publish your project (don't leave it in testing mode).

Drop the new API, Client Id and Secret onto your libreelec install, validate both apps and you should be away.

(I spent most of today messing about with this and then found that creating the new project fix about an hour ago via this thread: Bug #856 - "Bergiu commented 10 days ago - anxdpanic/plugin.video.youtube#50 (comment) - you need to recreate the full project")

Hope that helps.

thekarlm avatar Jan 01 '21 11:01 thekarlm

Also, do not forget to add test user if app is not pubished (is under testing) on google console.

hgabor-mad avatar Mar 21 '21 04:03 hgabor-mad

Thank you for this post. it resolved my issues.

ImportedMixes avatar Jan 03 '22 15:01 ImportedMixes

Just tried with a fresh install (latest master), even created a new project @google, but still get the same error:

LoginException: [401] invalid_client: The OAuth client was not found.

metux avatar Apr 20 '23 19:04 metux

Since this all causes so much trouble for so many people, the best would be rewriting the whole logic to not using the google api at all and parsing HTML.

metux avatar Apr 20 '23 19:04 metux

@metux That would effectively be a new plugin. There are other plugins that work that way already, if that's what you're looking for. I believe Invidious is one of those.

ThubLives avatar Apr 20 '23 20:04 ThubLives

@metux That would effectively be a new plugin. There are other plugins that work that way already, if that's what you're looking for. I believe Invidious is one of those.

thanks for the tip. but Invidious doesnt even want to start (seems to be unmaintained for many years).

meanwhile tried to set api key manually (via api_keys.json), show up in settings, but the plugin still wants to do the "login twice" stuff, which isnt working at all.

metux avatar Apr 20 '23 20:04 metux

@metux That would effectively be a new plugin. There are other plugins that work that way already, if that's what you're looking for. I believe Invidious is one of those.

thanks for the tip. but Invidious doesnt even want to start (seems to be unmaintained for many years).

This github repo was updated last week. I installed it using the provided repo on the github page. You might have to try a different instance in the settings.

meanwhile tried to set api key manually (via api_keys.json), show up in settings, but the plugin still wants to do the "login twice" stuff, which isnt working at all.

It's always going to want to authorise twice because it uses two APIs to do everything it does.

As for why it's not working, I'm not sure, but according to most tutorials for setting up the API keys, one of them has some extra text on the end that you don't need; I always trim it off and it has worked for me.

ThubLives avatar Apr 20 '23 20:04 ThubLives

It's always going to want to authorise twice because it uses two APIs to do everything it does.

As for why it's not working, I'm not sure, but according to most tutorials for setting up the API keys, one of them has some extra text on the end that you don't need; I always trim it off and it has worked for me.

When API keys are defined, why doesn't it use them. I could understand that, if something's wrong with the keys, I'll get an error, but I don't understand why it still wants to do the device peering (where I have to enter the one time key via web). By the way: everytime I do through this (and it fails), the keys are gone.

metux avatar Apr 21 '23 07:04 metux

When API keys are defined, why doesn't it use them. I could understand that, if something's wrong with the keys, I'll get an error, but I don't understand why it still wants to do the device peering (where I have to enter the one time key via web). By the way: everytime I do through this (and it fails), the keys are gone.

When you create your own API keys and enter them in the configuration, you are effectively giving the Kodi YouTube plugin a new identity; YouTube thinks it's a unique video player with its own quotas and everything. The device peering process is necessary for Google to protect your account.

From Google's perspective, some new application is trying to access your account and asking for permission to access a certain set of information from your account. The Google Accounts service doesn't necessarily validate the API keys since it doesn't have much information about what they are going to be used for, it only notices that they haven't been authorised to access your account. These API keys are only truly meaningful to YouTube, which is separate from the Google Accounts service.

Once the authorisation is done on Google's end, the YouTube plugin can use that generic authorisation with the YouTube APIs to request the information it needs to get started. My understanding is that it's at this point that we find out whether the API keys are working. If we make a request and the response contains the information we need, all is good. If not, there are a number of potential reasons that could be, a bad API key only being one, which is why the error messages tend not to be very helpful.

In any case, hopefully this explains why you have to go through the login and double-device pairing each time you enter something in the API keys. As for why you have to re-enter the API keys every time, I can only speculate, but I suspect that it's a simple compromise due to limitations in Kodi.

ThubLives avatar Apr 21 '23 14:04 ThubLives