From e38fdee66d5741125f15149e49c7fcdb8e4a9280 Mon Sep 17 00:00:00 2001 From: jellejurre Date: Mon, 25 Nov 2024 13:55:30 +0100 Subject: [PATCH 1/2] Improve examples --- examples/examples-source/cookies_load.py | 33 +++++++++++++++++++ .../{use_the_api.py => cookies_store.py} | 14 +++----- examples/examples-source/login.py | 6 ++-- 3 files changed, 41 insertions(+), 12 deletions(-) create mode 100644 examples/examples-source/cookies_load.py rename examples/examples-source/{use_the_api.py => cookies_store.py} (74%) diff --git a/examples/examples-source/cookies_load.py b/examples/examples-source/cookies_load.py new file mode 100644 index 00000000..69349ce2 --- /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 = "MyProject/1.0 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 74% rename from examples/examples-source/use_the_api.py rename to examples/examples-source/cookies_store.py index 34410efb..81ddb3ab 100644 --- a/examples/examples-source/use_the_api.py +++ b/examples/examples-source/cookies_store.py @@ -4,12 +4,9 @@ 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: @@ -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..8efcd4cb 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...) @@ -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) From 78adb2b2ad09f8f3d66bfdf8907db4776dc66147 Mon Sep 17 00:00:00 2001 From: jellejurre Date: Mon, 25 Nov 2024 18:38:50 +0100 Subject: [PATCH 2/2] Update user agent --- README.md | 2 +- examples/README.md | 6 +++--- examples/examples-source/cookies_load.py | 2 +- examples/examples-source/cookies_store.py | 2 +- examples/examples-source/login.py | 2 +- examples/examples-source/noauth.py | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) 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 index 69349ce2..56cbf55b 100644 --- a/examples/examples-source/cookies_load.py +++ b/examples/examples-source/cookies_load.py @@ -22,7 +22,7 @@ def make_cookie(name, value): ) 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" api_client.rest_client.cookie_jar.set_cookie( make_cookie("auth", "[AUTH_COOKIE_HERE]")) api_client.rest_client.cookie_jar.set_cookie( diff --git a/examples/examples-source/cookies_store.py b/examples/examples-source/cookies_store.py index 81ddb3ab..45b0e0ed 100644 --- a/examples/examples-source/cookies_store.py +++ b/examples/examples-source/cookies_store.py @@ -10,7 +10,7 @@ ) 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: diff --git a/examples/examples-source/login.py b/examples/examples-source/login.py index 8efcd4cb..25f19403 100644 --- a/examples/examples-source/login.py +++ b/examples/examples-source/login.py @@ -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) 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)