|
| 1 | +/* |
| 2 | + * Copyright 2020 Google Inc. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package com.google.firebase.example; |
| 17 | + |
| 18 | +import com.google.firebase.auth.DeleteUsersResult; |
| 19 | +import com.google.firebase.auth.EmailIdentifier; |
| 20 | +import com.google.firebase.auth.ErrorInfo; |
| 21 | +import com.google.firebase.auth.FirebaseAuth; |
| 22 | +import com.google.firebase.auth.GetUsersResult; |
| 23 | +import com.google.firebase.auth.PhoneIdentifier; |
| 24 | +import com.google.firebase.auth.ProviderIdentifier; |
| 25 | +import com.google.firebase.auth.UidIdentifier; |
| 26 | +import com.google.firebase.auth.UserIdentifier; |
| 27 | +import com.google.firebase.auth.UserRecord; |
| 28 | +import java.util.Arrays; |
| 29 | + |
| 30 | +public class FirebaseAuthSnippets { |
| 31 | + |
| 32 | + public static void bulkGetUsers() throws Exception { |
| 33 | + // [START bulk_get_users] |
| 34 | + GetUsersResult result = FirebaseAuth.getInstance().getUsersAsync(Arrays.asList( |
| 35 | + new UidIdentifier("uid1"), |
| 36 | + new EmailIdentifier( "[email protected]"), |
| 37 | + new PhoneIdentifier("+15555550003"), |
| 38 | + new ProviderIdentifier("google.com", "google_uid4"))).get(); |
| 39 | + |
| 40 | + System.out.println("Successfully fetched user data:"); |
| 41 | + for (UserRecord user : result.getUsers()) { |
| 42 | + System.out.println(user.getUid()); |
| 43 | + } |
| 44 | + |
| 45 | + System.out.println("Unable to find users corresponding to these identifiers:"); |
| 46 | + for (UserIdentifier uid : result.getNotFound()) { |
| 47 | + System.out.println(uid); |
| 48 | + } |
| 49 | + // [END bulk_get_users] |
| 50 | + } |
| 51 | + |
| 52 | + public static void bulkDeleteUsers() throws Exception { |
| 53 | + // [START bulk_delete_users] |
| 54 | + DeleteUsersResult result = FirebaseAuth.getInstance().deleteUsersAsync( |
| 55 | + Arrays.asList("uid1", "uid2", "uid3")).get(); |
| 56 | + |
| 57 | + System.out.println("Successfully deleted " + result.getSuccessCount() + " users"); |
| 58 | + System.out.println("Failed to delete " + result.getFailureCount() + " users"); |
| 59 | + for (ErrorInfo error : result.getErrors()) { |
| 60 | + System.out.println("error #" + error.getIndex() + ", reason: " + error.getReason()); |
| 61 | + } |
| 62 | + // [END bulk_delete_users] |
| 63 | + } |
| 64 | +} |
0 commit comments