diff --git a/README.md b/README.md index 53749ce6..fc81de40 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ configuration = vrchatapi.Configuration( # Enter a context with an instance of the API client with vrchatapi.ApiClient(configuration) as api_client: # Set our User-Agent as per VRChat Usage Policy - api_client.user_agent = "MyProject/1.0 my@email.com" + api_client.user_agent = "ExampleProgram/0.0.1 my@email.com" # Instantiate instances of API classes auth_api = authentication_api.AuthenticationApi(api_client) diff --git a/examples/README.md b/examples/README.md index fde31310..f6239992 100644 --- a/examples/README.md +++ b/examples/README.md @@ -21,7 +21,7 @@ configuration = vrchatapi.Configuration( # Enter a context with an instance of the API client with vrchatapi.ApiClient(configuration) as api_client: # Set our User-Agent as per VRChat Usage Policy - api_client.user_agent = "MyProject/1.0 my@email.com" + api_client.user_agent = "ExampleProgram/0.0.1 my@email.com" # Instantiate instances of API classes auth_api = authentication_api.AuthenticationApi(api_client) @@ -68,7 +68,7 @@ configuration = vrchatapi.Configuration( ) with vrchatapi.ApiClient(configuration) as api_client: - api_client.user_agent = "MyProject/1.0 my@email.com" + api_client.user_agent = "ExampleProgram/0.0.1 my@email.com" auth_api = authentication_api.AuthenticationApi(api_client) try: @@ -121,7 +121,7 @@ from vrchatapi.api.worlds_api import WorldsApi # We don't add a configuration file/set a username and password with vrchatapi.ApiClient() as api_client: - api_client.user_agent = "MyProject/1.0 my@email.com" + api_client.user_agent = "ExampleProgram/0.0.1 my@email.com" # We don't use the authentication API at all, since we don't need to world_api = WorldsApi(api_client) diff --git a/examples/examples-source/cookies_load.py b/examples/examples-source/cookies_load.py new file mode 100644 index 00000000..56cbf55b --- /dev/null +++ b/examples/examples-source/cookies_load.py @@ -0,0 +1,33 @@ +import vrchatapi +from http.cookiejar import Cookie + +from vrchatapi.api import authentication_api + + +def make_cookie(name, value): + return Cookie(0, name, value, + None, False, + "api.vrchat.cloud", True, False, + "/", False, + False, + 173106866300, + False, + None, + None, {}) + + +configuration = vrchatapi.Configuration( + username='username', + password='password', +) + +with vrchatapi.ApiClient(configuration) as api_client: + api_client.user_agent = "ExampleProgram/0.0.1 my@email.com" + api_client.rest_client.cookie_jar.set_cookie( + make_cookie("auth", "[AUTH_COOKIE_HERE]")) + api_client.rest_client.cookie_jar.set_cookie( + make_cookie("twoFactorAuth", "[TWO_FACTOR_AUTH_COOKIE_HERE]")) + + auth_api = authentication_api.AuthenticationApi(api_client) + current_user = auth_api.get_current_user() + print("Logged in as:", current_user.display_name) diff --git a/examples/examples-source/use_the_api.py b/examples/examples-source/cookies_store.py similarity index 71% rename from examples/examples-source/use_the_api.py rename to examples/examples-source/cookies_store.py index 34410efb..45b0e0ed 100644 --- a/examples/examples-source/use_the_api.py +++ b/examples/examples-source/cookies_store.py @@ -4,16 +4,13 @@ from vrchatapi.models.two_factor_auth_code import TwoFactorAuthCode from vrchatapi.models.two_factor_email_code import TwoFactorEmailCode -# We import the class that corrisponds to the section of the API we want to use -from vrchatapi.api.worlds_api import WorldsApi - configuration = vrchatapi.Configuration( - username = 'username', - password = 'password', + username='username', + password='password', ) with vrchatapi.ApiClient(configuration) as api_client: - api_client.user_agent = "MyProject/1.0 my@email.com" + api_client.user_agent = "ExampleProgram/0.0.1 my@email.com" auth_api = authentication_api.AuthenticationApi(api_client) try: @@ -30,8 +27,7 @@ except vrchatapi.ApiException as e: print("Exception when calling API: %s\n", e) + cookie_jar = api_client.rest_client.cookie_jar._cookies["vrchat.com"]["/"] print("Logged in as:", current_user.display_name) - - # Now we are logged in, we can init and use the API class :) - worlds_api = WorldsApi(api_client) # All API section classes require an ApiClient object to be passed! - active_worlds = worlds_api.get_active_worlds() \ No newline at end of file + print("auth: " + cookie_jar["auth"].value) + print("twoFactorAuth: " + cookie_jar["twoFactorAuth"].value) diff --git a/examples/examples-source/login.py b/examples/examples-source/login.py index 535ef3db..25f19403 100644 --- a/examples/examples-source/login.py +++ b/examples/examples-source/login.py @@ -6,8 +6,8 @@ from vrchatapi.models.two_factor_email_code import TwoFactorEmailCode configuration = vrchatapi.Configuration( - username = 'username', - password = 'password', + username='username', + password='password', ) # Step 2. VRChat consists of several API's (WorldsApi, UsersApi, FilesApi, NotificationsApi, FriendsApi, etc...) @@ -16,7 +16,7 @@ # Enter a context with an instance of the API client with vrchatapi.ApiClient(configuration) as api_client: # Set our User-Agent as per VRChat Usage Policy - api_client.user_agent = "MyProject/1.0 my@email.com" + api_client.user_agent = "ExampleProgram/0.0.1 my@email.com" # Instantiate instances of API classes auth_api = authentication_api.AuthenticationApi(api_client) @@ -38,4 +38,4 @@ except vrchatapi.ApiException as e: print("Exception when calling API: %s\n", e) - print("Logged in as:", current_user.display_name) \ No newline at end of file + print("Logged in as:", current_user.display_name) diff --git a/examples/examples-source/noauth.py b/examples/examples-source/noauth.py index 01abf9d6..30c486bb 100644 --- a/examples/examples-source/noauth.py +++ b/examples/examples-source/noauth.py @@ -5,7 +5,7 @@ # We don't add a configuration file/set a username and password with vrchatapi.ApiClient() as api_client: - api_client.user_agent = "MyProject/1.0 my@email.com" + api_client.user_agent = "ExampleProgram/0.0.1 my@email.com" # We don't use the authentication API at all, since we don't need to world_api = WorldsApi(api_client)