我必须将我的服务器授权给Firebase以获取Firebase SDK。但不幸的是,我无法读取credentials.json文件。我已将service.json文件放入WEB-INF文件夹中。
我已将此添加到我的appengine-web.xml文件中:
<resource-files>
<include path="/service.json"/>
</resource-files>
我正在尝试使用以下代码读取文件:
FirebaseOptions options = new FirebaseOptions.Builder().setServiceAccount(ServletServletContext.class.getResourceAsStream("/WEB-INF/service.json"))
但是当我尝试读取文件时,我得到一个NullPointerException。
这是我的全班:
@Api(
name = "myApi",
version = "v1",
namespace = @ApiNamespace(
ownerDomain = "backend",
ownerName = "backend",
packagePath=""
)
)
public class MyEndpoint {
private static final Logger log = Logger.getLogger(MyEndpoint.class.getName());
private String uid;
@ApiMethod(name = "signup")
public MyBean signup(@Named("token")String token)
{
uid = "empty";
uid = "init";
log.info(new File(getClass().getResource("/WEB-INF/service.json").toString()).exists()+"");
FirebaseOptions options = new FirebaseOptions.Builder()
.setServiceAccount(getClass().getResourceAsStream("/WEB-INF/service.json"))
.setDatabaseUrl("url")
.build();
FirebaseApp.initializeApp(options);
uid = "initialized";
log.severe("initialized");
FirebaseAuth.getInstance().verifyIdToken(token)
.addOnSuccessListener(new OnSuccessListener<FirebaseToken>() {
@Override
public void onSuccess(FirebaseToken decodedToken) {uid = decodedToken.getUid();
}
});
MyBean b = new MyBean();
if(!uid.equals(""))
b.setData(uid);
// else
// b.setData("failed");
return b;
}
}
提前感谢您的帮助。
答案 0 :(得分:1)
您可以使用
KdTree BBox3