Skip to content

Commit 6b0d59e

Browse files
committed
Add API example
1 parent 4f65a70 commit 6b0d59e

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

‎examples/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<dependency>
2424
<groupId>com.github.vrchatapi</groupId>
2525
<artifactId>vrchatapi-java</artifactId>
26-
<version>1.0.1-globalcookie2</version>
26+
<version>1.0.1-globalcookie3</version>
2727
</dependency>
2828
</dependencies>
2929
</project>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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

Comments
 (0)