Address
Address は、mixi2 Application API の公式エンドポイント/アドレスを定数として提供するヘルパーです。環境変数や設定ファイルに固定値を持たせる必要がなくなり、コード上で明示的に参照できます。
インストール
Section titled “インストール”追加インストールは不要です。mixi2-js に同梱されています。
// ESMimport { tokenUrl, apiAddress, streamAddress } from 'mixi2-js/helpers';// CJSconst { tokenUrl, apiAddress, streamAddress } = require('mixi2-js/helpers');import { tokenUrl, apiAddress, streamAddress } from '@otoneko1102/mixi2-js/helpers';なぜ Address を使うのか?
Section titled “なぜ Address を使うのか?”アクセストークンの取得 URL や API サーバーアドレスは固定値ですが、手入力やコピペではミスが起きやすいです。
// ❌ 固定値を手書きconst authenticator = new OAuth2Authenticator({ clientId, clientSecret, tokenUrl: 'https://application-auth.mixi.social/oauth2/token',});
const client = new Client({ apiAddress: 'application-api.mixi.social', authenticator,});Address を使えば、公式の値をそのまま再利用できます:
// ✅ 公式アドレスを参照const authenticator = new OAuth2Authenticator({ clientId, clientSecret, tokenUrl,});
const client = new Client({ apiAddress, authenticator,});基本的な使い方
Section titled “基本的な使い方”import { OAuth2Authenticator, Client, StreamWatcher,} from 'mixi2-js';import { tokenUrl, apiAddress, streamAddress } from 'mixi2-js/helpers';import { OAuth2Authenticator, Client, StreamWatcher,} from '@otoneko1102/mixi2-js';import { tokenUrl, apiAddress, streamAddress } from '@otoneko1102/mixi2-js/helpers';const authenticator = new OAuth2Authenticator({ clientId: process.env.CLIENT_ID!, clientSecret: process.env.CLIENT_SECRET!, tokenUrl,});
const client = new Client({ apiAddress, authenticator,});
const watcher = new StreamWatcher({ streamAddress, authenticator,});API リファレンス
Section titled “API リファレンス”| 定数 | 型 | 説明 |
|---|---|---|
tokenUrl | string | アクセストークン取得用エンドポイント URL |
apiAddress | string | gRPC API サーバーアドレス |
streamAddress | string | gRPC ストリーミング接続用サーバーアドレス |
| 定数 | 値 |
|---|---|
tokenUrl | https://application-auth.mixi.social/oauth2/token |
apiAddress | application-api.mixi.social |
streamAddress | application-stream.mixi.social |