Firebase ID令牌验证 - Java NoSuchMethod

时间:2017-01-29 18:18:27

标签: java firebase netbeans firebase-admin


我尝试使用Firebase Admin SDK在Netbeans中创建一个简单的服务器。我尝试在服务器上验证ID令牌,但我得到了 错误

Exception in thread "pool-1-thread-2" java.lang.NoSuchMethodError: com.google.api.client.googleapis.auth.oauth2.GoogleCredential.getServiceAccountProjectId()Ljava/lang/String;
at com.google.firebase.auth.FirebaseAuth$2.then(FirebaseAuth.java:157)
at com.google.firebase.auth.FirebaseAuth$2.then(FirebaseAuth.java:152)
at com.google.firebase.tasks.ContinueWithCompletionListener$1.run(ContinueWithCompletionListener.java:33)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

这是代码

public static void main(String[] args) throws FileNotFoundException {
    FileInputStream serviceAccount = new FileInputStream("E:\\Letöltések\\...");

    FirebaseOptions options = new FirebaseOptions.Builder()
            .setServiceAccount(serviceAccount)
      .setDatabaseUrl("https://... .firebaseio.com")
      .build();

    FirebaseApp defaultApp = FirebaseApp.initializeApp(options);
    System.out.println(defaultApp.getName());

    FirebaseAuth defaultAuth = FirebaseAuth.getInstance(defaultApp);
    FirebaseDatabase defaultDatabase = FirebaseDatabase.getInstance(defaultApp);

    String idToken = getIdToken(); //"eyJhb..."

    FirebaseAuth.getInstance().verifyIdToken(idToken)
    .addOnSuccessListener(new OnSuccessListener<FirebaseToken>() {
            @Override
            public void onSuccess(FirebaseToken decodedToken) {
                String uid = decodedToken.getUid();
                System.out.println("UID: " + uid);
            }
    });
}

1 个答案:

答案 0 :(得分:0)

Firebase Admin Node.js SDK的最新4.0.4版本中存在一个错误(在我们的发行说明here中注明)。要解决此问题,您可以降级到版本$enqq = "insert into enquires2(name,email,phone,message,current_date)values('$name','$email','$phone','$message',NOW())"; 。我们将在本周早些时候推出一个新版本,并解决这个问题。对不起任何麻烦!