GoogleCredentials不起作用并使应用程序瘫痪

时间:2019-06-01 00:41:00

标签: firebase

我遵循了文档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;
    }

1 个答案:

答案 0 :(得分:0)

解决了!我不得不在项目中包括这些书店

  • api-common-1.8.1
  • commons-logging-1.2
  • firebase-admin-6.8.1
  • google-api-client-1.29.0
  • google-http-client-1.29.1
  • google-http-client-gson-1.29.1
  • google-http-client-jackson2-1.29.1
  • google-oauth-client-1.29.0
  • gson-2.8.5
  • guava-27.1-jre
  • httpclient-4.5.8
  • httpcore-4.4.11
  • jackson-core-2.9.9
  • jackson-core-asl-1.9.13
  • jsr305-3.0.2
  • protobuf-java-3.8.0
  • slf4j-api-1.7.26
  • slf4j-simple-1.7.26
  • xpp3-1.1.6

https://mvnrepository.com/中有其更新的版本