如何使用firebase REST API将java连接到firebase?

如何使用firebase REST API将java连接到firebase?,java,firebase,Java,Firebase,以下是firebase API提供的演示java代码。我如何使用它?似乎没有办法将maven包导入到我自己的项目中 package net.thegreshams.firebase4j.demo; import java.io.IOException; import java.util.LinkedHashMap; import java.util.Map; import net.thegreshams.firebase4j.error.Firebas

以下是firebase API提供的演示java代码。我如何使用它?似乎没有办法将maven包导入到我自己的项目中

    package net.thegreshams.firebase4j.demo;

    import java.io.IOException;
    import java.util.LinkedHashMap;
    import java.util.Map;

    import net.thegreshams.firebase4j.error.FirebaseException;
    import net.thegreshams.firebase4j.error.JacksonUtilityException;
    import net.thegreshams.firebase4j.model.FirebaseResponse;
    import net.thegreshams.firebase4j.service.Firebase;

    import org.codehaus.jackson.JsonParseException;
    import org.codehaus.jackson.map.JsonMappingException;

    public class Demo {

    public static void main(String[] args) throws FirebaseException, JsonParseException, JsonMappingException, IOException, JacksonUtilityException {


    // get the base-url (ie: 'http://gamma.firebase.com/username')
    String firebase_baseUrl = null;
    for( String s : args ) {

        if( s == null || s.trim().isEmpty() ) continue;
        if( s.trim().split( "=" )[0].equals( "baseUrl" ) ) {
            firebase_baseUrl = s.trim().split( "=" )[1];
        }
    }
    if( firebase_baseUrl == null || firebase_baseUrl.trim().isEmpty() ) {
        throw new IllegalArgumentException( "Program-argument 'baseUrl' not found but required" );
    }


    // create the firebase
    Firebase firebase = new Firebase( firebase_baseUrl );


    // "DELETE" (the fb4jDemo-root)
    FirebaseResponse response = firebase.delete();


    // "PUT" (test-map into the fb4jDemo-root)
    Map<String, Object> dataMap = new LinkedHashMap<String, Object>();
    dataMap.put( "PUT-root", "This was PUT into the fb4jDemo-root" );
    response = firebase.put( dataMap );
    System.out.println( "\n\nResult of PUT (for the test-PUT to fb4jDemo-root):\n" + response );
    System.out.println("\n");


    // "GET" (the fb4jDemo-root)
    response = firebase.get();
    System.out.println( "\n\nResult of GET:\n" + response );
    System.out.println("\n");


    // "PUT" (test-map into a sub-node off of the fb4jDemo-root)
    dataMap = new LinkedHashMap<String, Object>();
    dataMap.put( "Key_1", "This is the first value" );
    dataMap.put( "Key_2", "This is value #2" );
    Map<String, Object> dataMap2 = new LinkedHashMap<String, Object>();
    dataMap2.put( "Sub-Key1", "This is the first sub-value" );
    dataMap.put( "Key_3", dataMap2 );
    response = firebase.put( "test-PUT", dataMap );
    System.out.println( "\n\nResult of PUT (for the test-PUT):\n" + response );
    System.out.println("\n");


    // "GET" (the test-PUT)
    response = firebase.get( "test-PUT" );
    System.out.println( "\n\nResult of GET (for the test-PUT):\n" + response );
    System.out.println("\n");


    // "POST" (test-map into a sub-node off of the fb4jDemo-root)
    response = firebase.post( "test-POST", dataMap );
    System.out.println( "\n\nResult of POST (for the test-POST):\n" + response );
    System.out.println("\n");


    // "DELETE" (it's own test-node)
    dataMap = new LinkedHashMap<String, Object>();
    dataMap.put( "DELETE", "This should not appear; should have been DELETED" );
    response = firebase.put( "test-DELETE", dataMap );
    System.out.println( "\n\nResult of PUT (for the test-DELETE):\n" + response );
    response = firebase.delete( "test-DELETE");
    System.out.println( "\n\nResult of DELETE (for the test-DELETE):\n" + response );
    response = firebase.get( "test-DELETE" );
    System.out.println( "\n\nResult of GET (for the test-DELETE):\n" + response );

}

}
package net.thegreshams.firebase4j.demo;
导入java.io.IOException;
导入java.util.LinkedHashMap;
导入java.util.Map;
导入net.thegreshams.firebase4j.error.FirebaseException;
导入net.thegreshams.firebase4j.error.JacksonUtilityException;
导入net.thegreshams.firebase4j.model.FirebaseResponse;
导入net.thegreshams.firebase4j.service.Firebase;
导入org.codehaus.jackson.JsonParseException;
导入org.codehaus.jackson.map.JsonMappingException;
公开课演示{
公共静态void main(字符串[]args)抛出FirebaseException、JsonParseException、JsonMappingException、IOException、JacksonUtilityException{
//获取基本url(即:'http://gamma.firebase.com/username')
字符串firebase_baseUrl=null;
for(字符串s:args){
如果(s==null | | s.trim().isEmpty())继续;
如果(s.trim().split(“=”[0])。等于(“baseUrl”)){
firebase_baseUrl=s.trim().split(“=”[1];
}
}
if(firebase_baseUrl==null | | firebase_baseUrl.trim().isEmpty()){
抛出新的IllegalArgumentException(“未找到程序参数'baseUrl',但为必需”);
}
//创建firebase
Firebase Firebase=新的Firebase(Firebase\u baseUrl);
//“删除”(fb4jDemo根目录)
FirebaseResponse=firebase.delete();
//“PUT”(测试映射到fb4jDemo根目录中)
Map dataMap=新建LinkedHashMap();
put(“put root”,“这被放入fb4jDemo根目录”);
响应=firebase.put(数据映射);
System.out.println(“\n\n PUT结果(对于fb4jDemo根的测试PUT):\n”+响应);
System.out.println(“\n”);
//“GET”(fb4jDemo根)
response=firebase.get();
System.out.println(“\n\n获取的结果:\n”+响应);
System.out.println(“\n”);
//“PUT”(测试映射到fb4jDemo根的子节点中)
dataMap=新建LinkedHashMap();
put(“Key_1”,“这是第一个值”);
放置(“键2”,“这是值2”);
Map dataMap2=新建LinkedHashMap();
dataMap2.put(“子键1”,“这是第一个子值”);
dataMap.put(“键3”,dataMap2);
响应=firebase.put(“测试put”,dataMap);
System.out.println(“\n\n输出结果(用于测试输出):\n”+响应);
System.out.println(“\n”);
//“GET”(测试PUT)
响应=firebase.get(“测试放置”);
System.out.println(“\n\n GET的结果(用于测试PUT):\n”+响应);
System.out.println(“\n”);
//“POST”(将测试映射到fb4jDemo根的子节点)
响应=firebase.post(“测试桩”,dataMap);
System.out.println(“\n\n POST结果(用于测试POST):\n”+响应);
System.out.println(“\n”);
//“删除”(它自己的测试节点)
dataMap=新建LinkedHashMap();
dataMap.put(“删除”,“不应该出现;应该删除”);
响应=firebase.put(“测试删除”,数据映射);
System.out.println(“\n\n PUT结果(用于测试删除):\n”+响应);
响应=firebase.delete(“测试删除”);
System.out.println(“\n\n删除结果(用于测试删除):\n”+响应);
响应=firebase.get(“测试删除”);
System.out.println(“\n\n GET的结果(用于测试删除):\n”+响应);
}
}
API开发人员还为firebase_url提供了以下消息,该url在上述代码中为空:

“若要使用此项目,您必须首先获取Firebase工作区url。您可以通过注册尽早访问其私人beta版来获取工作区url。”

问题:第二句话是什么意思?有人能说得更清楚些吗?我真的需要工作区url,我是的作者

虽然我很喜欢看到人们对我的项目感兴趣,但它非常过时,没有得到很好的支持(因为缺乏时间和兴趣);我同意其他人对它的拉动请求,但在其他方面,我并没有对它进行太多维护。它最初是一个POC,后来有一天我醒来,人们都在使用它(我觉得很好,但买家要小心,诸如此类)。如果这个项目实际上填补了官方工具没有提供的空白,那么我完全愿意让人们提交新特性的请求,并让项目继续下去;但是当我创建这个项目时,我包装了Firebase REST API,因为它们没有正式的Java支持——然而,现在,这不再是事实()

然而,为了回答这里提出的实际问题,我从项目自述中引用:

要使用此项目,必须首先获取Firebase工作区url。您可以通过注册尽早访问他们的私有测试版来获得工作区url

或者,您可以运行他们的教程,然后使用教程提供的自动生成的工作区url。然而,这个url是暂时的,所以不要把任何你想保留的数据放在那里

您还应该查看Firebase文档和教程,因为此接口仅用于为RESTAPI提供一个薄包装

首先,考虑文件是指FialBASE“早期访问他们的私人测试版”——这种情况不再相关。但基本上它只是告诉你去Firebase注册一个开发者帐户;你可以登录Firebase.google.com登录Firebase

关于工作区url,这只是对您在Firebase.google.com上定义Firebase项目时创建的Firebase工作区的引用。在这里,我们不打算向您介绍这一点,但我相信教程会介绍这一点——当您阅读完他们的教程时,您可能会决定使用工具tha