为了验证从客户端应用程序发送的Firebase令牌,我有以下代码:
Task<FirebaseToken> authTask = FirebaseAuth.getInstance().verifyIdToken("very long string token").addOnSuccessListener(new OnSuccessListener() {
@Override
public void onSuccess(Object tr) { }
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception excptn) { }
}).addOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(Task task) { }
});
try {
Tasks.await(authTask);
} catch(ExecutionException | InterruptedException e ){
//handle error
}
FirebaseToken decodedToken = authTask.getResult();
String uid = decodedToken.getUid();
通过Maven / google后端api部署时,我收到以下错误:
java.lang.IllegalStateException:名称为[DEFAULT]的FirebaseApp不存在
我该如何解决?
答案 0 :(得分:2)
您必须在Google云端控制台上设置服务帐户。阅读Docs。
将服务帐户密钥文件(.json)放入/resources/META-INF/
目录。
确保您已将资源文件包含在appengine-web.xml
<!-- Include resource files -->
<resource-files>
<include path="/**.json" />
<include path="/**.xml" />
<include path="/**.properties" />
</resource-files>
FirebaseOptions
文件传递service_account_key.json
以初始化FirebaseApp
。您可以在Warmup Servlet。public void init(ServletConfig config) throws ServletException {
InputStream loadedServiceAccount = config
.getServletContext()
.getResourceAsStream("/WEB-INF/service_account_key.json");
FirebaseOptions options = new FirebaseOptions.Builder()
.setServiceAccount(loadedServiceAccount)
.setDatabaseUrl("URL_FIREBASE_DATABASE").build();
FirebaseApp firebaseApp = FirebaseApp.initializeApp(options);
FirebaseAuth.getInstance(firebaseApp);
}
FirebaseAuth.getInstance()
。当您的AppEngine实例运行测试版(可能是1.9.44)时,它将为您提供noMethodFoundError。然后你可以继续这个Question。