使用 java admin SDK 连接到 Firebase Emulator Suite 时,如何在没有现有服务帐户凭据的情况下初始化应用程序?我有环境变量FIREBASE_DATABASE_EMULATOR_HOST=localhost:9000
设置好后,模拟器就开始运行了。然后我使用以下代码初始化应用程序:
FirebaseApp.initializeApp(FirebaseOptions.builder()
.setCredentials(GoogleCredentials.getApplicationDefault())
.setDatabaseUrl("http://localhost:9000?ns=my-project-id")
.build(), "my-project-id");
但我得到了例外:
java.io.IOException: The Application Default Credentials are not available.
They are available if running in Google Compute Engine.
Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined
pointing to a file defining the credentials.
See https://developers.google.com/accounts/docs/application-default-credentials for more information.
即使我只想使用模拟器,我是否始终需要拥有现有的服务帐户?我可以使用模拟器的某种虚拟服务帐户凭据吗?
您可以像这样传递假凭证:
GoogleCredentials.create(new AccessToken(
"mock-token",
Date.from(LocalDateTime.now().plusYears(1).atZone(ZoneId.systemDefault()).toInstant())));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)