VRChat APIの非公式Goクライアントライブラリ
- シンプルで使いやすいAPI
- Cookieベースのセッション管理
- 2要素認証対応
- 型安全なエラーハンドリング
- 設定可能なHTTPクライアント(プロキシ、タイムアウト、User-Agent)
- WebSocketサポート - リアルタイムイベント受信(通知、フレンド状態、ロケーション変更など)
go get github.com/kqnade/vrcgopackage main
import (
"context"
"log"
"github.com/kqnade/vrcgo/shared"
"github.com/kqnade/vrcgo/vrcapi"
)
func main() {
client, err := vrcapi.NewClient()
if err != nil {
log.Fatal(err)
}
// 認証
err = client.Authenticate(context.Background(), shared.AuthConfig{
Username: "your-username",
Password: "your-password",
})
if err != nil {
log.Fatal(err)
}
// ユーザー情報取得
user, err := client.GetCurrentUser(context.Background())
if err != nil {
log.Fatal(err)
}
log.Printf("Logged in as: %s", user.DisplayName)
}client, _ := vrcapi.NewClient()
// Cookieを読み込み
if err := client.LoadCookies("cookies.json"); err != nil {
log.Fatal(err)
}
// ユーザー情報取得(Cookie認証)
user, err := client.GetCurrentUser(context.Background())
if err != nil {
log.Fatal(err)
}client, err := vrcapi.NewClient(
vrcapi.WithUserAgent("my-app/1.0"),
vrcapi.WithTimeout(30 * time.Second),
vrcapi.WithProxy("http://proxy.example.com:8080"),
)import (
"github.com/kqnade/vrcgo/shared"
"github.com/kqnade/vrcgo/vrcapi"
"github.com/kqnade/vrcgo/vrcws"
)
// WebSocket接続
ws, err := vrcws.New(context.Background(), client)
if err != nil {
log.Fatal(err)
}
defer ws.Close()
// フレンドがオンラインになったときの処理
ws.OnFriendOnline(func(friend shared.FriendOnlineEvent) {
log.Printf("%s is now online at %s", friend.UserID, friend.Location)
})
// 通知を受信
ws.OnNotification(func(notification shared.NotificationEvent) {
log.Printf("Notification: %s", notification.Message)
})
// すべてのイベントをログ
ws.On("*", func(event shared.Event) {
log.Printf("Event: %s", event.Type)
})
// 接続を維持
ws.Wait()サンプルコードは examples/ ディレクトリにあります:
# 基本認証の例
export VRCHAT_USERNAME="your-username"
export VRCHAT_PASSWORD="your-password"
make run-basic-auth
# Cookie認証の例
make run-cookie-auth
# WebSocketでリアルタイムイベントを受信
export VRCHAT_USERNAME="your-username"
export VRCHAT_PASSWORD="your-password"
make run-websocketAuthenticate(ctx, config)- ユーザー名/パスワードでログイン(2FA対応)GetCurrentUser(ctx)- 現在のユーザー情報を取得Logout(ctx)- ログアウト
GetUser(ctx, userId)- ユーザー情報を取得GetUserByName(ctx, username)- ユーザー名からユーザー情報を取得SearchUsers(ctx, opts)- ユーザーを検索UpdateUser(ctx, userId, req)- ユーザー情報を更新GetUserGroups(ctx, userId)- ユーザーのグループリストを取得GetUserRepresentedGroup(ctx, userId)- 代表グループを取得
GetFriends(ctx, opts)- フレンドリストを取得GetFriendStatus(ctx, userId)- フレンドステータスを取得SendFriendRequest(ctx, userId)- フレンドリクエストを送信DeleteFriend(ctx, userId)- フレンドを削除AcceptFriendRequest(ctx, notificationId)- フレンドリクエストを承認DeclineFriendRequest(ctx, notificationId)- フレンドリクエストを拒否GetOnlineFriends(ctx)- オンラインフレンドを取得GetOfflineFriends(ctx)- オフラインフレンドを取得
GetAvatar(ctx, avatarId)- アバター情報を取得SearchAvatars(ctx, opts)- アバターを検索SelectAvatar(ctx, avatarId)- アバターを装着CreateAvatar(ctx, req)- アバターを作成UpdateAvatar(ctx, avatarId, req)- アバター情報を更新DeleteAvatar(ctx, avatarId)- アバターを削除GetFavoriteAvatars(ctx)- お気に入りアバターを取得
GetWorld(ctx, worldId)- ワールド情報を取得SearchWorlds(ctx, opts)- ワールドを検索GetActiveWorlds(ctx)- アクティブなワールドを取得GetRecentWorlds(ctx)- 最近訪問したワールドを取得GetFavoriteWorlds(ctx)- お気に入りワールドを取得CreateWorld(ctx, req)- ワールドを作成UpdateWorld(ctx, worldId, req)- ワールド情報を更新DeleteWorld(ctx, worldId)- ワールドを削除GetWorldMetadata(ctx, worldId)- ワールドメタデータを取得PublishWorld(ctx, worldId)- ワールドを公開UnpublishWorld(ctx, worldId)- ワールドを非公開化
GetInstance(ctx, worldId, instanceId)- インスタンス情報を取得GetInstanceByShortName(ctx, shortName)- 短縮名でインスタンスを取得SendSelfInvite(ctx, worldId, instanceId)- 自分自身に招待を送信CreateInstance(ctx, req)- インスタンスを作成CloseInstance(ctx, worldId, instanceId)- インスタンスを閉じる
GetNotifications(ctx, opts)- 通知リストを取得MarkNotificationAsRead(ctx, notificationId)- 通知を既読にするDeleteNotification(ctx, notificationId)- 通知を削除ClearAllNotifications(ctx)- すべての通知をクリアSendNotification(ctx, req)- 通知を送信SendInvite(ctx, userId, req)- インスタンス招待を送信RespondToInvite(ctx, notificationId, req)- 招待に応答RequestInvite(ctx, userId, instanceLocation)- 招待をリクエスト
AddFavorite(ctx, req)- お気に入りを追加RemoveFavorite(ctx, favoriteId)- お気に入りを削除GetFavorites(ctx, opts)- お気に入りリストを取得GetFavoriteGroups(ctx, type)- お気に入りグループを取得UpdateFavoriteGroup(ctx, type, name, userId, req)- お気に入りグループを更新ClearFavoriteGroup(ctx, type, name, userId)- お気に入りグループをクリア
GetGroup(ctx, groupId)- グループ情報を取得SearchGroups(ctx, opts)- グループを検索CreateGroup(ctx, req)- グループを作成UpdateGroup(ctx, groupId, req)- グループ情報を更新DeleteGroup(ctx, groupId)- グループを削除JoinGroup(ctx, groupId)- グループに参加LeaveGroup(ctx, groupId)- グループから脱退GetGroupMembers(ctx, groupId, n, offset)- グループメンバーを取得BanGroupMember(ctx, groupId, userId)- メンバーをBANUnbanGroupMember(ctx, groupId, userId)- メンバーのBANを解除CreateGroupAnnouncement(ctx, groupId, req)- グループアナウンスを作成DeleteGroupAnnouncement(ctx, groupId, announcementId)- アナウンスを削除
GetFile(ctx, fileId)- ファイル情報を取得CreateFile(ctx, req)- ファイルを作成DeleteFile(ctx, fileId)- ファイルを削除DownloadFile(ctx, fileId, version)- ファイルダウンロードURLを取得CreateFileVersion(ctx, fileId, req)- ファイルバージョンを作成DeleteFileVersion(ctx, fileId, version)- ファイルバージョンを削除
ModerateUser(ctx, req)- ユーザーをモデレートGetPlayerModerations(ctx)- モデレーションリストを取得MuteUser(ctx, userId)- ユーザーをミュートUnmuteUser(ctx, userId)- ミュートを解除BlockUser(ctx, userId)- ユーザーをブロックUnblockUser(ctx, userId)- ブロックを解除HideUserAvatar(ctx, userId)- アバターを非表示ShowUserAvatar(ctx, userId)- アバターを表示
GetConfig(ctx)- システム設定を取得GetSystemTime(ctx)- サーバー時刻を取得GetInfoPushes(ctx)- 情報プッシュを取得GetCurrentOnlineUsers(ctx)- オンラインユーザー数を取得GetHealth(ctx)- APIヘルスチェック
SaveCookies(path)- Cookieをファイルに保存LoadCookies(path)- Cookieをファイルから読み込み
ConnectWebSocket(ctx)- WebSocket接続を確立ws.On(eventType, handler)- イベントハンドラーを登録ws.OnNotification(handler)- 通知イベントws.OnFriendOnline(handler)- フレンドオンラインイベントws.OnFriendOffline(handler)- フレンドオフラインイベントws.OnFriendLocation(handler)- フレンドロケーション変更イベントws.OnFriendActive(handler)- フレンドアクティブイベントws.OnFriendAdd(handler)- フレンド追加イベントws.OnFriendDelete(handler)- フレンド削除イベントws.OnUserUpdate(handler)- ユーザー更新イベントws.Close()- WebSocket接続を閉じるws.Wait()- 接続終了まで待機
対応イベント一覧:
notification- 通知friend-online- フレンドがオンラインにfriend-offline- フレンドがオフラインにfriend-active- フレンドがアクティブにfriend-location- フレンドのロケーション変更friend-add- フレンド追加friend-delete- フレンド削除friend-update- フレンド情報更新user-update- ユーザー情報更新user-location- ユーザーロケーション変更notification-v2- 通知V2notification-v2-update- 通知V2更新notification-v2-delete- 通知V2削除group-joined- グループ参加group-left- グループ脱退group-member-updated- グループメンバー更新group-role-updated- グループロール更新
err := client.Authenticate(ctx, config)
if err != nil {
if vrchat.IsAuthenticationError(err) {
log.Println("Invalid credentials")
} else if vrchat.IsRateLimitError(err) {
log.Println("Rate limited")
} else if vrchat.IsNotFoundError(err) {
log.Println("Resource not found")
} else {
log.Printf("Error: %v", err)
}
}make buildmake testmake fmtmake vet- これはコミュニティ主導のプロジェクトであり、VRChat公式サポートはありません
- Photonサーバーへの直接アクセスは禁止されています
- APIのレート制限を遵守してください
- VRChatの利用規約に従ってください
Apache-2.0