[GH-ISSUE #708] OAuth Web client does not work #461

Closed
opened 2026-02-27 23:00:55 +03:00 by kerem · 4 comments
Owner

Originally created by @pranavbhandari24 on GitHub (Dec 29, 2024).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/708

Issue
When using the client ID and client secret for Oauth, if the client ID is a webclient ytmusicapi oauth fails with

ytmusicapi.auth.oauth.exceptions.BadOAuthClient: OAuth client failure. Most likely client_id and client_secret mismatch or YouTubeData API is not enabled.

I also tried to create oauth.json manually (by generating the access token but I get 401 Unauthorized error

Traceback (most recent call last):
  File "/Users/pranavbhandari/PycharmProjects/MoveMusic/youtube_music.py", line 117, in <module>
    result = ytmusic.get_library_songs(limit=library_limit)
  File "/Users/pranavbhandari/PycharmProjects/MoveMusic/.venv/lib/python3.9/site-packages/ytmusicapi/mixins/library.py", line 81, in get_library_songs
    response = parse_func(request_func(None))
  File "/Users/pranavbhandari/PycharmProjects/MoveMusic/.venv/lib/python3.9/site-packages/ytmusicapi/mixins/library.py", line 69, in <lambda>
    request_func = lambda additionalParams: self._send_request(endpoint, body)
  File "/Users/pranavbhandari/PycharmProjects/MoveMusic/.venv/lib/python3.9/site-packages/ytmusicapi/ytmusic.py", line 278, in _send_request
    raise YTMusicServerError(message + error)
ytmusicapi.exceptions.YTMusicServerError: Server returned HTTP 401: Unauthorized.
You must be signed in to perform this operation.

To Reproduce
Create a Web OAuth client and use that in ytmusicapi oauth

Note: If the client is a TV client, everything works as expected. I need a web client to specify callback urls

Originally created by @pranavbhandari24 on GitHub (Dec 29, 2024). Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/708 **Issue** When using the client ID and client secret for Oauth, if the client ID is a webclient `ytmusicapi oauth` fails with ``` ytmusicapi.auth.oauth.exceptions.BadOAuthClient: OAuth client failure. Most likely client_id and client_secret mismatch or YouTubeData API is not enabled. ``` I also tried to create `oauth.json` manually (by generating the access token but I get 401 Unauthorized error ``` Traceback (most recent call last): File "/Users/pranavbhandari/PycharmProjects/MoveMusic/youtube_music.py", line 117, in <module> result = ytmusic.get_library_songs(limit=library_limit) File "/Users/pranavbhandari/PycharmProjects/MoveMusic/.venv/lib/python3.9/site-packages/ytmusicapi/mixins/library.py", line 81, in get_library_songs response = parse_func(request_func(None)) File "/Users/pranavbhandari/PycharmProjects/MoveMusic/.venv/lib/python3.9/site-packages/ytmusicapi/mixins/library.py", line 69, in <lambda> request_func = lambda additionalParams: self._send_request(endpoint, body) File "/Users/pranavbhandari/PycharmProjects/MoveMusic/.venv/lib/python3.9/site-packages/ytmusicapi/ytmusic.py", line 278, in _send_request raise YTMusicServerError(message + error) ytmusicapi.exceptions.YTMusicServerError: Server returned HTTP 401: Unauthorized. You must be signed in to perform this operation. ``` **To Reproduce** Create a Web OAuth client and use that in `ytmusicapi oauth` **Note**: If the client is a TV client, everything works as expected. I need a web client to specify callback urls
kerem closed this issue 2026-02-27 23:00:55 +03:00
Author
Owner

@pranavbhandari24 commented on GitHub (Dec 30, 2024):

Oh, this was my mistake. I was not adding the "expires_at" and "expires_in" to the manually created oauth.json. Once I added those the requests worked as expected.

ytmusicapi oauth still fails when using web oauth client though.

<!-- gh-comment-id:2564938228 --> @pranavbhandari24 commented on GitHub (Dec 30, 2024): Oh, this was my mistake. I was not adding the "expires_at" and "expires_in" to the manually created oauth.json. Once I added those the requests worked as expected. `ytmusicapi oauth` still fails when using web oauth client though.
Author
Owner

@sigma67 commented on GitHub (Dec 31, 2024):

ytmusicapi oauth still fails when using web oauth client though.

Could you elaborate?

<!-- gh-comment-id:2566236476 --> @sigma67 commented on GitHub (Dec 31, 2024): > ytmusicapi oauth still fails when using web oauth client though. Could you elaborate?
Author
Owner

@pranavbhandari24 commented on GitHub (Jan 24, 2025):

ytmusicapi oauth still fails when using web oauth client though.

Could you elaborate?

ytmusicapi oauth command fails when I provide Web OAuth client, but works as expected when I provide a TV Oauth client

<!-- gh-comment-id:2612214247 --> @pranavbhandari24 commented on GitHub (Jan 24, 2025): > > ytmusicapi oauth still fails when using web oauth client though. > > Could you elaborate? `ytmusicapi oauth` command fails when I provide Web OAuth client, but works as expected when I provide a TV Oauth client
Author
Owner

@sigma67 commented on GitHub (Jan 24, 2025):

@pranavbhandari24 that is expected, hence the advice in the documentation to create TV credentials

https://ytmusicapi.readthedocs.io/en/stable/setup/oauth.html

<!-- gh-comment-id:2612304105 --> @sigma67 commented on GitHub (Jan 24, 2025): @pranavbhandari24 that is expected, hence the advice in the documentation to create TV credentials https://ytmusicapi.readthedocs.io/en/stable/setup/oauth.html
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ytmusicapi#461
No description provided.