|
| 1 | +package io.github.vrchatapi.demo; |
| 2 | + |
| 3 | +import java.util.List; |
| 4 | +import java.util.Map.Entry; |
| 5 | +import java.util.stream.Collectors; |
| 6 | + |
| 7 | +import io.github.vrchatapi.*; |
| 8 | +import io.github.vrchatapi.auth.*; |
| 9 | +import io.github.vrchatapi.api.*; |
| 10 | +import io.github.vrchatapi.model.*; |
| 11 | + |
| 12 | +public class Demo { |
| 13 | + |
| 14 | + public static void main(String[] args) throws ApiException { |
| 15 | + // Step 1. VRChat consists of several API's |
| 16 | + // e.g. (WorldsApi, UsersApi, FilesApi, NotificationsApi, FriendsApi, etc...) |
| 17 | + // Here we instantiate the Authentication API which is required for logging in. |
| 18 | + // We also instantiate the System API for fetching the API key needed for future requests. |
| 19 | + ApiClient defaultClient = Configuration.getDefaultApiClient(); |
| 20 | + AuthenticationApi authApi = new AuthenticationApi(defaultClient); |
| 21 | + SystemApi systemApi = new SystemApi(defaultClient); |
| 22 | + |
| 23 | + // Step 2. We begin with creating a Configuration |
| 24 | + // This contains the username and password for authentication. |
| 25 | + HttpBasicAuth authHeader = (HttpBasicAuth) defaultClient.getAuthentication("authHeader"); |
| 26 | + authHeader.setUsername("username"); |
| 27 | + authHeader.setPassword("password"); |
| 28 | + // Also fetch API key. Fetching the Config sets the API key as a cookie. |
| 29 | + systemApi.getConfig(); |
| 30 | + |
| 31 | + // Step 3. Call getCurrentUser on Authentication API. |
| 32 | + // This logs you in if the user isn't already logged in. |
| 33 | + CurrentUser result = authApi.getCurrentUser(); |
| 34 | + System.out.println(result.getDisplayName()); |
| 35 | + |
| 36 | + System.exit(0); |
| 37 | + } |
| 38 | + |
| 39 | +} |
0 commit comments