Authenticate Client¶
API authentication is required to use some features of the chzzkpy package.
Client¶
You must complete Generate an Application.
Once the process is complete, the client can be authenticate using the Client ID and Client secret.
import chzzkpy
client_id = "CLIENT ID"
client_secret = "CLIENT SECRET"
client = chzzkpy.Client(client_id, client_secret)
User Client¶
Note
In order to authenticate the UserClient, the Client must be authenticated.
UserClient authentication is based on the OAuth2 process. This is two methods to authenticate UserClient.
Using
generate_authorization_token_urlandgenerate_user_clientmethods.authorization_url = client.generate_authorization_token_url( redirect_url="https://localhost:8080/", state="abcd12345" ) print(f"Please login with this url: {authorization_url}") code = input("Please input response code: ") user_client = await client.generate_user_client(code, "abcd12345") # await user_client.fetch_self() print(user_client.channel_id)Get the URL for OAuth2 authentication through
generate_authorization_token_urlmethod. If third-party authentication is successful, it is returned with a code query in the redirection URL.To authenticate, enter the code in the redirect URL into the
generate_user_clientmethod.Using
Client.loginmethod with temporary HTTP server.user_client = await client.login()When
client.loginmethod is executed, a temporary web server for authentication is launched and a browser opens. Once authentication is complete, the web server terminates and returnsUserClient.
(Legacy) Client / ChatClient¶
An unofficial API-based client use NID_AUT and NID_SES cookies for authentication.
This cookie is used to verify your Naver account, so it should not be shared with others.
import chzzkpy.unofficial
NID_AUT = "Authenticate Cookie key"
NID_SES = "Session Cookie key"
client = chzzkpy.unofficial.Client()
client.login(NID_AUT, NID_SES)