This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void initWithAppDefaultCredentials() { | |
// ADC does not require any explicit credential files. | |
FirebaseOptions options = new FirebaseOptions.Builder() | |
.setCredentials(GoogleCredentials.getApplicationDefault()) | |
.build(); | |
FirebaseApp.initializeApp(options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void initWithServiceAccountCredentials() { | |
// Service account must be specified explicitly. | |
FileInputStream serviceAccount = new FileInputStream("path/to/serviceAccount.json"); | |
FirebaseOptions options = new FirebaseOptions.Builder() | |
.setCredentials(GoogleCredentials.fromStream(serviceAccount)) | |
.build(); | |
FirebaseApp.initializeApp(options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"rules": { | |
"users": { | |
"$uid": { | |
".write": "$uid === auth.uid" | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void initWithLimitedPrivileges() { | |
// Initialize the app with a custom auth variable, limiting the server's access | |
Map<String, Object> auth = new HashMap<String, Object>(); | |
auth.put("uid", "my-service-worker"); | |
FirebaseOptions options = new FirebaseOptions.Builder() | |
.setCredentials(GoogleCredentials.getApplicationDefault()) | |
.setDatabaseUrl("https://databaseName.firebaseio.com") | |
.setDatabaseAuthVariableOverride(auth) | |
.build(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.api.core.ApiFuture; | |
import com.google.api.core.ApiFutureCallback; | |
import com.google.api.core.ApiFutures; | |
@Deprecated | |
public void addTaskCallbacks(Task<String> task) { | |
task.addOnSuccessListener(new OnSuccessListener<String>() { | |
@Override | |
public void onSuccess(String result) { | |
System.out.println("Operation completed with result: " + result); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.api.core.ApiFunction; | |
import com.google.api.core.ApiFuture; | |
import com.google.api.core.ApiFutures; | |
@Deprecated | |
public Task<List<String>> continueWithTask(Task<String> task) { | |
return task.continueWith(new Continuation<String, List<String>>() { | |
@Override | |
public List<String> then(Task<String> task) throws Exception { | |
String result = task.getResult(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.api.core.ApiFutures; | |
import com.google.firebase.tasks.Tasks; | |
String value = "value"; | |
Exception error = new Exception("custom error"); | |
// Wrap in Tasks | |
Task<String> valueTask = Tasks.forResult(value); | |
Task<String> exceptionTask = Tasks.forException(error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.firebase.tasks.Tasks; | |
@Deprecated | |
public String waitForTask(Task<String> task) { | |
try { | |
return Tasks.await(task); | |
} catch (ExecutionException | InterruptedException e) { | |
throw new RuntimeException("Error while waiting for task", e); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.api.core.SettableApiFuture; | |
import com.google.firebase.tasks.TaskCompletionSource; | |
@Deprecated | |
public Task<String> incompleteTask() { | |
final TaskCompletionSource<String> source = new TaskCompletionSource<>(); | |
new Thread() { | |
@Override | |
public void run() { | |
try { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Start listing users from the beginning, 1000 at a time. | |
ListUsersPage page = FirebaseAuth.getInstance().listUsersAsync(null).get(); | |
while (page != null) { | |
for (ExportedUserRecord user : page.getValues()) { | |
System.out.println("User: " + user.getUid()); | |
} | |
page = page.getNextPage(); | |
} | |
// Iterate through all users. This will still retrieve users in batches, |
OlderNewer