我遵循了文档https://firebase.google.com/docs/admin/setup?authuser=0
的步骤但是代码的“ GoogleCredentials.fromStream(serviceAccount)”部分;它会停止应用程序,并且不返回任何内容,甚至不会返回错误消息。
我已经包含了以下库
firebase-admin-6.8.1.jar
google-auth-library-credentials-0.15.0.jar
google-auth-library-oauth2-http-0.15.0.jar
appengine-api-1.0-sdk-1.9.74.jar
请给我一些帮助,谢谢
String token=null;
FirebaseOptions options=null;
FileInputStream serviceAccount=null;
try {
serviceAccount = new FileInputStream(Aplicacion.ruta_firebase_js);
}catch(FileNotFoundException ex) {
log("Ruta de clave de firebase no encontrada: "+ex.getMessage());
}
if(serviceAccount!=null){
try {
GoogleCredentials gc=GoogleCredentials.fromStream(serviceAccount);
log(gc.toString());
options = new FirebaseOptions.Builder()
.setCredentials(gc)
.setDatabaseUrl("https://xxxxx-xxxxxx.firebaseio.com")
.build();
} catch(FileNotFoundException ex) {
log("Ruta de clave de firebase no encontrada: "+ex.getMessage());
}catch (IOException ex){
log("Error autenticando en Firebase: "+ex.getMessage());
}
}
if(options!=null){
FirebaseApp.initializeApp(options);
try {
String uid = "Rocco-ergvrw98";
token = FirebaseAuth.getInstance().createCustomToken(uid);
HashMap p=new HashMap();
p.put("accion", "tokenfirebase");
p.put("token", token);
Rocco.servidor_enlinealizate.enviar(indice, p);
} catch (FirebaseAuthException ex) {
log("Error obtenmiendo token: "+ex.getMessage());
};
}
return token;
}
答案 0 :(得分:0)
解决了!我不得不在项目中包括这些书店
https://mvnrepository.com/中有其更新的版本