1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【VRChat API】別のアカウントでfavoriteしたワールド(アカウント)を別のアカウントにコピーする

Last updated at Posted at 2021-08-09

VRChat APIを使うため、諸注意に留意してください :)

$ ./favorite.sh world_id_list.json worlds1 auth=authcookie_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
This world is favorite:
  favoriteId: wrld_6c828572-43da-49cd-b320-ef799438d189
  tags: ["worlds2"]
Skip this world:
  favoriteId: wrld_c710e8be-2e4b-407c-869e-0c3d5a3786e1
  error message: "world not found"
This world is favorite:
  favoriteId: wrld_d6dae663-d775-4967-9f59-1a47b48df247
  tags: ["worlds2"]

...

これは完全なプログラムではないので、使用する前に下記の手順で補完する必要があります。

(プログラムはMITライセンスで配布しているので、改良してくれてもいいのよ><)

準備

  1. apiKeyを取得: https://vrchatapi.github.io/#/GettingStarted/QuickStart?id=client-api-key
$ apiKey=$(curl https://api.vrchat.cloud/api/1/config | jq '.apiKey')
  1. 下記にも設定してください(下記の値は現在のもの)
$ cat favorite.sh | head -3
# !/bin/bash

apiKey=JlE5Jldo5Jibnk5O5hTx6XVqsJu4WJ26

コピー元アカウント側の準備

  1. いつもの(2FAを使っている場合はこちらから
$ echo -n 'your_old_vrchat_account_id:password' | base64
XXXXXXXXXXXXXXXX=

$ auth_plain='XXXXXXXXXXXXXXXX='
  1. authcookieを取得: auth=authcookie_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXの部分をコピーしておく
$ curl --verbose \
    'https://api.vrchat.cloud/api/1/auth/user?apiKey=$apiKey' \
    -H "Authorization: Basic $auth_plain" 2>&1 \
    | grep 'auth=authcookie_'
< set-cookie: auth=authcookie_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX; Max-Age=604800; Path=/; Expires=Mon, 16 Aug 2021 07:33:02 GMT; HttpOnly

$ auth_cookie='auth=authcookie_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'

2FAを使っている場合は、かわりにこちらを実行します

$ otp={2FAアプリから取得}
$ curl -X POST \
  'https://api.vrchat.cloud/api/1/auth/twofactorauth/totp/verify' \
    -H "Authorization: Basic $auth_plain" \
    -d "code=$otp" \
    2>&1 \
    | grep 'auth=authcookie_'
< set-cookie: auth=authcookie_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX; Max-Age=604800; Path=/; Expires=Mon, 16 Aug 2021 07:33:02 GMT; HttpOnly

$ auth_cookie='auth=authcookie_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'

  1. favorite済みワールドの取得

n=100は重要なので、省略しないでね!

(デフォルトだと20個くらいの取得になってしまう)


100が上限なので、100以上のワールドfavoriteがある場合はできない……?

'【VRChat API】favorite済みワールド全てをunfavoriteする'を併用すると、よさそう

$ curl "https://api.vrchat.cloud/api/1/favorites?apiKey=$apiKey&type=world&n=100" \
    -b "$auth_cookie" \
    > favorites.json

$ cat favorites.json | jq '.[].favoriteId' | tee worlds.json
"wrld_7a88c811-7a97-4fcc-ad83-d295e5f177c1"
"wrld_72fab76b-651d-443d-87d7-326c4e8528a0"
...

必要に応じて、favorite枠ごとにjsonを分割してください
分割した場合は、下記のworlds1.jsonのようなファイルを、以降のworlds.jsonと同じように処理してください

$ cat favorites.json | jq '.[] | select(.tags[] | contains("worlds1"))' | worlds1.json

jqわかんないので、手動でjsonの形に直します
ここのやり方わかる人、この記事にPRください!

$ $EDITOR worlds.json
$ cat worlds.json
[
  "wrld_7a88c811-7a97-4fcc-ad83-d295e5f177c1",
  ...
  "wrld_72fab76b-651d-443d-87d7-326c4e8528a0"
]

コピー先アカウント側の準備

  1. 上記「いつもの」と同じ(2FAを使っている場合は同じくこちら
$ echo -n 'your_new_vrchat_account_id:password' | base64
XXXXXXXXXXXXXXXX=

$ auth_plain=$(echo -n 'your_new_vrchat_account_id:password' | base64)
  1. authcookieを取得: auth=authcookie_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXXの部分をコピーしておく
$ curl --verbose \
    'https://api.vrchat.cloud/api/1/auth/user?apiKey=$apiKey' \
    -H "Authorization: Basic $auth_plain" 2>&1 \
    | grep 'auth=authcookie_'
< set-cookie: auth=authcookie_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX; Max-Age=604800; Path=/; Expires=Mon, 16 Aug 2021 07:33:02 GMT; HttpOnly

$ auth_cookie='auth=authcookie_XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
  1. 実際にfavoriteに登録する

とうとうやるぞ!!

favorite枠が通常は64個なのに気を付けて、切り分けておきます

例えば今favorite枠worlds1が24つのみ余っている場合は分割しておきます

$ jq '.[:24]' < worlds.json > part.json

ちゅーこってやっとこれです
'favorite.sh - GitHub Gist'をダウンロードしてきてね><

VRChatアカウントのBANを回避するために、1分に1つのワールドを処理します
お茶を飲んでまってましょう :tea:

$ ./favorite.sh part.json worlds1 "$auth_cookie"

これが終わって、お茶も飲み終わったなら、残りも処理しちゃいましょう

# worlds2が35枠余ってる
$ jq ".[24:$((24 + 35))]" < worlds.json > part2.json
$ ./favorite.sh part2.json worlds2 "$auth_cookie"

# worlds3の枠がいっぱい余ってる
$ jq ".[$((24 + 35)):]" < worlds.json > part3.json
$ ./favorite.sh part3.json worlds3 "$auth_cookie"

おわり

おわり

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?