android - How to use Firebase REST API in Java? -
i need able update data firebase without setting firebase online specified data gets sent while no wifi available. have been unable find documents or guides on how use rest api in java. can me it?
unfortunately there isn't existing java sdk firebase rest interface (that find). instead you'll need make 1 using http client of choice.
here's example using jersey:
import javax.ws.rs.core.mediatype; import com.sun.jersey.api.client.client; import com.sun.jersey.api.client.clienthandlerexception; import com.sun.jersey.api.client.uniforminterfaceexception; import com.vnomicscorp.firebase.sdk.firebasesdk; import com.vnomicscorp.firebase.sdk.firebasesdkexception; public class firebasesdkjersey { private static final string default_auth_param_name = "auth"; private static final string default_path_format = "%s.json"; private final string credentials; private final string url; private final client client; private string authparamname = default_auth_param_name; private string pathformat = default_path_format; public firebasesdkjersey(string url, string credentials, client client) { this.url = url; this.credentials = credentials; this.client = client; } public void setvalue(string path, string value) throws exception { client.resource(url).path(string.format(pathformat, path)) .queryparam(authparamname, credentials) .type(mediatype.application_json).entity(value) .put(string.class); } public string getvalue(string path) throws exception { return client.resource(url).path(string.format(pathformat, path)) .queryparam(authparamname, credentials).get(string.class); } public void deletevalue(string path) throws exception { client.resource(url).path(string.format(pathformat, path)) .queryparam(authparamname, credentials).delete(string.class); } }
needs following dependencies
<dependency> <groupid>com.sun.jersey</groupid> <artifactid>jersey-client</artifactid> <version>1.19</version> </dependency>
construction looks this:
client client = client.create(); sdk = new firebasesdkjersey(url, credentials, client);
where url
firebase url , credentials
secret key generated in admin console.
Comments
Post a Comment