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