@@ -28,7 +28,9 @@ Below is an example on how to login to the API and fetch your own user informati
2828``` python
2929# Step 1. We begin with creating a Configuration, which contains the username and password for authentication.
3030import vrchatapi
31- from vrchatapi.api import authentication_api, users_api
31+ from vrchatapi.api import authentication_api
32+ from vrchatapi.exceptions import UnauthorizedException
33+ from vrchatapi.model.two_factor_auth_code import TwoFactorAuthCode
3234
3335configuration = vrchatapi.Configuration(
3436 username = ' username' ,
@@ -47,9 +49,17 @@ with vrchatapi.ApiClient(configuration) as api_client:
4749 try :
4850 # Step 3. Calling getCurrentUser on Authentication API logs you in if the user isn't already logged in.
4951 current_user = auth_api.get_current_user()
50- print (" Logged in as:" , current_user.display_name)
52+ except UnauthorizedException as e:
53+ if UnauthorizedException.status == 200 :
54+ # Step 3.5. Calling verify2fa if the account has 2FA enabled
55+ auth_api.verify2_fa(two_factor_auth_code = TwoFactorAuthCode(input (" 2FA Code: " )))
56+ current_user = auth_api.get_current_user()
57+ else :
58+ print (" Exception when calling API: %s \n " , e)
5159 except vrchatapi.ApiException as e:
5260 print (" Exception when calling API: %s \n " , e)
61+
62+ print (" Logged in as:" , current_user.display_name)
5363```
5464
5565See [ example.py] ( https://github.com/vrchatapi/vrchatapi-python/blob/main/example.py ) for more example usage on getting started.
0 commit comments