Debian Codegraph @

docs/source/setup/oauth.rst

raw
1 OAuth authentication
2 ====================
3
4 .. attention::
5
6 As of November 2024, YouTube Music requires a Client Id and Secret for the YouTube Data API to connect to the API.
7
8 Go to the `YouTube Data API docs <https://developers.google.com/youtube/registering_an_application>`_ to
9 obtain the credentials. This requires a Google Cloud Console account and project.
10
11 For your new credentials, select ``OAuth client ID`` and pick ``TVs and Limited Input devices``.
12
13 After you have installed ``ytmusicapi``, run
14
15 .. code-block:: bash
16
17 ytmusicapi oauth
18
19 and follow the instructions. This will create a file ``oauth.json`` in the current directory.
20
21 You can pass this file to :py:class:`YTMusic` as explained in :doc:`../usage`.
22
23 You will also need to pass ``client_id`` and ``client_secret`` to :py:class:`YTMusic`:
24
25 .. code-block::
26
27 from ytmusicapi import YTMusic, OAuthCredentials
28
29 ytmusic = YTMusic('oauth.json', oauth_credentials=OAuthCredentials(client_id=client_id, client_secret=client_secret))
30
31 This OAuth flow uses the
32 `Google API flow for TV devices <https://developers.google.com/youtube/v3/guides/auth/devices>`_.