既定フィールド
Kii Cloud SDK は、以下の情報を管理するための既定フィールドを定義しています。
フィールド | JSON でのフィールド名 | 説明 |
---|---|---|
ユーザー ID | userID | REST API などで使用する文字列形式のユーザー ID です。1234567-89ab-cdef-0123-456789abcdef のような形式です。 |
内部ユーザー ID | internalUserID | 内部的に使用している数値のユーザー ID です。 |
ユーザー名 | loginName | ログインで使用するユーザー名です。ユーザー名の指定がないとき、フィールドはありません。 |
メールアドレス | emailAddress | ログインで使用するメールアドレスです。メールアドレスの指定がないとき、フィールドはありません。 |
メールアドレスが確認済みかどうか | emailAddressVerified | ログインで使用するメールアドレスを認証する設定で確認済みのとき true、未確認のとき false です。認証機能を使用しないときは true です。 |
電話番号 | phoneNumber | ログインで使用する電話番号です。指定方法によらず、常に国際電話番号の形式で保存されます。電話番号を指定しないとき、フィールドはありません。 |
電話番号が確認済みかどうか | phoneNumberVerified | ログインで使用する電話番号を認証する設定で確認済みのとき true、未確認のとき false です。認証機能を使用しないときは true です。 |
ディスプレイネーム | displayName | システム的に特に意味は持ちません。モバイルアプリで自由に使用できます。ディスプレイネームを指定しないとき、フィールドはありません。Unicode で 1~50 文字の範囲で入力します。 |
所在国 | country | US 、JP 、CN などが入ります。値を設定していない場合、フィールドはありません。電話番号として国内電話番号形式を指定した場合に限り、国際電話番号形式に変換するための情報としても使用されます( JP を設定して電話番号に 09011111111 を指定すると、+819011111111 に自動変換)。逆に、国際電話番号から所在国を自動設定したり、所在国から国際電話番号形式の電話番号を自動修正したりする機能はありません。 |
ロケール | locale | ユーザーのロケールです。メールアドレスや電話番号の認証を行う際、ここで設定したロケールのテンプレートが使用されます。 |
ログイン中のユーザー以外からユーザー属性を取得する場合、"Expose Full User Data to Others" オプションの変更が必要なものがあります。オプション設定によってはユーザー ID、ユーザー名、ディスプレイネームしか取得されません。詳細は、他ユーザーの属性の読み込み を参照してください。
既定フィールドの設定と変更
ユーザーの既定フィールドの設定・変更には IdentityData
クラスと UserFields
クラスを利用します。IdentityData
クラスと UserFields
クラスにはそれぞれ以下のフィールドを設定します。
IdentityData
- ユーザー名
- メールアドレス
- 電話番号
UserFields
- ディスプレイネーム
- 所在国
- ロケール
ユーザー ID はユーザー作成時に自動的に生成されます。変更はできません。
ユーザーの既定フィールドを設定・変更する例を以下に挙げます。
-
try { // Set the username, email address, and phone number. IdentityData.Builder builder = IdentityData.Builder.newWithName("user_123456"); builder.withEmail("user_123456@example.com") .withPhone("+919012345678"); IdentityData identityData = builder.build(); // Set the display name, country, and locale. UserFields userFields = new UserFields(); userFields.putDisplayName("My_New_Name"); userFields.putCountry("US"); userFields.putLocale(new LocaleContainer(Locale.getDefault())); // Get the currently logged-in user. KiiUser user = KiiUser.getCurrentUser(); // Update the user attributes. user.update(identityData, userFields); } catch (IOException e) { // Handle the error. } catch (AppException e) { // Handle the error. }
-
// Set the username, email address, and phone number. IdentityData.Builder builder = IdentityData.Builder.newWithName("user_123456"); builder.withEmail("user_123456@example.com") .withPhone("+919012345678"); IdentityData identityData = builder.build(); // Set the display name, country, and locale. UserFields userFields = new UserFields(); userFields.putDisplayName("My_New_Name"); userFields.putCountry("US"); userFields.putLocale(new LocaleContainer(Locale.getDefault())); // Get the currently logged-in user. KiiUser user = KiiUser.getCurrentUser(); // Update the user attributes. user.update(identityData, userFields, new KiiUserUpdateCallback() { @Override public void onUpdateCompleted(KiiUser kiiUser, Exception exception) { if (exception != null) { // Handle the error. return; } } });
既存のフィールドを更新対象として指定しない場合、そのフィールドはそのまま Kii Cloud 上に保持されます。
update()
メソッドが正常に完了すると、フィールドが Kii Cloud および KiiUser
インスタンスで更新されます。
なお、認証がオンの状態でメールアドレスや電話番号を変更した場合は認証処理が実行されます。新たに設定したメールアドレスや電話番号によるログインは、この認証処理が完了するまで有効になりません。詳しくは メールアドレス認証 および 電話番号(SMS)認証 を参照してください。
既定フィールドの参照
ユーザーの既定フィールドを参照する例を以下に挙げます。
-
// Get the currently logged-in user. KiiUser user = KiiUser.getCurrentUser(); try { // Refresh the user to get the latest user info from Kii Cloud. user.refresh(); // Get the user attributes. String userId = user.getID(); String userName = user.getUsername(); String emailAddress = user.getEmail(); String phoneNumber = user.getPhone(); String displayName = user.getDisplayname(); String country = user.getCountry(); LocaleContainer localeContainer = user.getLocale(); } catch (IOException e) { // Handle the error. } catch (AppException e) { // Handle the error. }
-
// Get the currently logged-in user. KiiUser user = KiiUser.getCurrentUser(); // Refresh the user to get the latest user info from Kii Cloud. user.refresh(new KiiUserCallBack() { @Override public void onRefreshCompleted(int token, Exception exception) { if (exception != null) { // Handle the error. return; } // Get the user attributes. String userId = user.getID(); String userName = user.getUsername(); String emailAddress = user.getEmail(); String phoneNumber = user.getPhone(); String displayName = user.getDisplayname(); String country = user.getCountry(); LocaleContainer localeContainer = user.getLocale(); } });