0


我尝试使用 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);
            }
    });
}
4

1 回答 1

0

Firebase Admin Node.js SDK的最新4.1.0版本中存在一个错误(在我们的发行说明中注明。要解决此问题,您可以降级到 version 4.0.4。我们将在本周早些时候推出一个新版本,并修复该问题。给您添麻烦了!

于 2017-01-30T06:09:12.313 回答