LoginSignup
9
2

More than 1 year has passed since last update.

VRChatでのフレンド行動ログを取得する

Posted at

概要

VRChatでのフレンドの行動(行っているワールド、誰と一緒にいるか)をログに残すことで
そのフレンドの人間関係、行動が分析できるはず。

本記事について

VRChatのAPIを使用しフレンドがいるワールド及びインスタンスの人数、
どのフレンドと一緒にいるかの情報取得方法を記載しています

環境

OS : Windows
Python : 3.8.8
Anaconda version : 4.10.1

VRChatのAPI接続方法

以下の記事をご覧ください

使用するエンドポイント

①フレンド全員の情報取得

https://api.vrchat.cloud/api/1/auth/user/friends

オンラインのフレンド全員の各情報(ユーザーID、ワールドなど)を取得します。

詳しい使用方法以下に記載されています。

②インスタンスの情報取得

https://api.vrchat.cloud/api/1/instances/[ID]:[INSTANCEID]

インスタンスにいる人数の情報を上記から取得します。
また、インスタンスマスターの情報も併せて取得できます。

詳しい使用方法以下に記載されています。

③ワールドの情報取得

https://api.vrchat.cloud/api/1/worlds/[ID]/[INSTANCEID]

ワールドの情報(ワールド名やトップ画像、説明分)を取得します。

詳しい使用方法以下に記載されています。

出力内容

te4tet4et.png

ログとして
[時間][ワールド名][インスタンス人数][インスタンス状態][同じインスタンスにいるフレンド]
の情報を取得することができます。

この情報を溜めることにより
インした時の行動、どのフレンドと仲が良いかなどの分析が可能です

ソース

import requests
import json
from urllib.parse import quote
from sys import exit
from datetime import datetime

def friend_logs():
    # 監視するユーザー名を記入
    user_name = ""

   # VRCのID、PWを取得
    credential = json.load(open('credential.json'))


    username = "VRCのID"
    password = "VRCのpassword"
    apiKey = 'JlE5Jldo5Jibnk5O5hTx6XVqsJu4WJ26'# 21/05/22 時点で公開されているキー
    data = {'apiKey':apiKey}
    headers = {'User-Agent': 'SunaFH/1.0.5'}
   
    response = requests.get('https://api.vrchat.cloud/api/1/auth/user', data=data, headers=headers, auth= username , password )))
    token = response.cookies["auth"]

    # auth/user/playermoderations endpoint よりmoderation情報を取得
    response = requests.get('https://api.vrchat.cloud/api/1/auth/user/friends', data=data, headers=headers, params={"authToken": token})
    moderations = response.json()
    friend_disturber_list = []

    #moderation情報より対象のlocationを取得
    instance_location = ""
    for i in (list(moderations)):
        if user_name == i["displayName"]:
            instance_location = i['location']

    if instance_location == "":
        return

    if instance_location != "private":
        #対象と一緒のインスタンスにいるフレンドを取得
        for i in (list(moderations)):
            if i['location'] == instance_location and i["displayName"] != user_name:
                friend_disturber_list.append(i["displayName"])

        locato = instance_location.split(":")

        #インスタンス人数、インスタンスの種類を取得
        response = requests.get('https://api.vrchat.cloud/api/1/instances/' + instance_location, data=data, headers=headers, params={"authToken": token})
        moderations = response.json()
        n_user = moderations['n_users']
        instance_type = moderations['type']
        if instance_type == "hidden":
            instance_type = "friends+"

        #ワールド名を取得
        response = requests.get('https://api.vrchat.cloud/api/1/worlds/' + locato[0], data=data, headers=headers, params={"authToken": token})
        moderations = response.json()
        world_name = moderations['name']
        #print(world_name)

        with open("players_log.txt", "a",encoding='utf-8') as opfile:
            opfile.write(u"{} {} {} {} {}\n".format(datetime.now(),world_name,n_user,instance_type,friend_disturber_list))
    else:
        with open("players_log.txt", "a",encoding='utf-8') as opfile:
            opfile.write(u"{} {}\n".format(datetime.now(),"private"))

終わりに

行動分析、人間関係の洗い出しは基本だよね

参考

9
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
2