Firebase Admin Java SDK不做任何操作 [英] Firebase Admin Java SDK not doing any operation
问题描述
我使用此指南设置了Firebase管理软件开发工具包p>
所以我用下面的方法初始化它:
InputStream refreshToken = new ClassPathResource(CONFIG_FILE).getInputStream();
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredential(FirebaseCredentials.fromRefreshToken(refreshToken))
.setDatabaseUrl(https://< project-id> ;. firebaseio.com/)
.build();
FirebaseApp.initializeApp(options);
我没有错误到这一点,一切似乎都很好。但是,我无法做任何操作。调用方法什么也不做。例如:
FirebaseDatabase.getInstance()
.getReference()
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot){
//此回调永远不会被调用
}
@Override
public void onCancelled(DatabaseError databaseError){
}
});
或
class Pojo {
public Pojo(String name,String surname){
this.name = name;
this.surname = surname;
}
字符串名称;
字符串姓氏;
//省略getters和setters
}
FirebaseDatabase.getInstance.getReference()
.push()
.setValue(new Pojo(Test,Test));
//这个值永远不会设置
它看起来像skd忽略了任何命令。任何想法?
$ b $背景:我在本地机器上运行它作为一个web应用程序(spring)。
fromCertificate()
方法,而不是< a href =https://firebase.google.com/docs/reference/admin/java/reference/com/google/firebase/auth/FirebaseCredentials.html#fromRefreshToken(java.io.InputStream) =nofollow noreferrer > fromRefreshToken()
方法: FileInputStream serviceAccount = new FileInputStream(path / to / serviceAccountKey.json);
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredential(FirebaseCredentials.fromCertificate(serviceAccount))
.setDatabaseUrl(https://< DATABASE_NAME> .firebaseio。 com /)
.build();
FirebaseApp.initializeApp(options);
使用刷新令牌进行身份验证有点高级用例,可能不是您想要的正在使用。
I've setup the firebase admin SDK using this guide
So I'm initializing it in the following way.
InputStream refreshToken = new ClassPathResource(CONFIG_FILE).getInputStream();
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredential(FirebaseCredentials.fromRefreshToken(refreshToken))
.setDatabaseUrl("https://<project-id>.firebaseio.com/")
.build();
FirebaseApp.initializeApp(options);
I got no errors to this point, everything seems fine. However, I'm unable to do any operations. Calling the methods does nothing. Eg:
FirebaseDatabase.getInstance()
.getReference()
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//this callback is never called
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
or
class Pojo {
public Pojo(String name, String surname) {
this.name = name;
this.surname = surname;
}
String name;
String surname;
//omitted getters and setters
}
FirebaseDatabase.getInstance.getReference()
.push()
.setValue(new Pojo("Test", "Test"));
//this value is never set
It simply looks like that the skd ignores any command. Any ideas?
Background: I'm running this as a web application (spring) on a local machine.
If you are authenticating the SDK with a service account key JSON file as documented in Add Firebase to your app, you should use the fromCertificate()
method, not the fromRefreshToken()
method:
FileInputStream serviceAccount = new FileInputStream("path/to/serviceAccountKey.json");
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredential(FirebaseCredentials.fromCertificate(serviceAccount))
.setDatabaseUrl("https://<DATABASE_NAME>.firebaseio.com/")
.build();
FirebaseApp.initializeApp(options);
Authenticating with a refresh token is a bit of an advanced use case and is probably not what you want to be using.
这篇关于Firebase Admin Java SDK不做任何操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!