A collection of quickstart samples demonstrating the Firebase APIs using the Admin Java SDK. For more information, see https://firebase.google.com.
Please read and follow the steps in the CONTRIBUTING.md
See LICENSE
Quickstart samples for Firebase Java Admin SDK
License: Apache License 2.0
A collection of quickstart samples demonstrating the Firebase APIs using the Admin Java SDK. For more information, see https://firebase.google.com.
Please read and follow the steps in the CONTRIBUTING.md
See LICENSE
Hello!
This project uses a very old Gradle Wrapper version 3.3. Check the file quickstart-java/gradle/wrapper/gradle-wrapper.properties
#Mon Jun 05 12:42:45 PDT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
And it leads to the error
Unable to start the daemon process.
The project uses Gradle 3.3 which is incompatible with Java 11 or newer.
Possible solution:
- Upgrade Gradle wrapper to 4.8.1 version and re-import the project
- Use Java 8 as Gradle JVM: Open Gradle settings
Could you please to update it to the most recent one?
Thank you,
Vagif
My application logs this line from time to time with log level WARN. As described in #5 this is expected behaviour, application recovers and works fine.
Please change log level for this message to DEBUG (or at least INFO).
WARN alerts admins and they involve devs to investigate which is unnecessary.
If created this issue in wrong project please point me to right one.
Best Regards
The example code only shows how to use the Http protocol connection to FCM.
There should also be an example using the Admin SDK.
When the server has been up and running for a while I get this. How can I make the token not expire?
I know this is not the right place to ask that kind to question here but I am not able to get more documentation on the following issue.
Question 1 .setCredentials() and Error:(33, 20) Failed to resolve: com.google.firebase:firebase-admin:11.8.0
FileInputStream serviceAccount = null;
try {
serviceAccount = new FileInputStream("path/to/serviceAccountKey.json");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.setDatabaseUrl("https://example.firebaseio.com/")
.build();
FirebaseApp.initializeApp(options);
Not able to find solution and documentation for this. After reading multiple instructions and documentation I found these following data
I use the java server side sample then change the my `project_id` variable in `com.google.firebase.quickstart.Messaging.java' . The following logs show in my project. I don't know why.
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:210)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
at sun.security.ssl.InputRecord.read(InputRecord.java:503)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1316)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1291)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:77)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:981)
at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:283)
at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307)
at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:384)
at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:489)
at jp.co.kyocera.thp.sendNotice.service.Messaging.getAccessToken(Messaging.java:50)
at jp.co.kyocera.thp.sendNotice.service.Messaging.getConnection(Messaging.java:68)
at jp.co.kyocera.thp.sendNotice.service.Messaging.sendMessage(Messaging.java:83)
at jp.co.kyocera.thp.sendNotice.service.Messaging.sendCommonMessage(Messaging.java:191)
Is auth possible using the "sever" library? It seems as if it was in the past, but I can't find any examples today.
https://github.com/firebase/firebase-simple-login-java
I created a Firebase project and downloaded this repo, created service-account.json.
In addition in the Database.java I added some sample code from the Firebase QuickStart Guide - Save Data to store some data. However I got the following error
[WARN] PersistentConnection: pc_0 - Authentication failed: invalid_token (Access denied.)
Here is my database rules.
{
"rules": {
".read": true,
".write": true
}
}
It should allows any read/write.
I have no idea how to get the auth done. Thanks for the help
the remote config sample wont work because newer versions os gradle/android studio wont accept the compile
instruction
I'm using below Java snippet to get the Authentication token for Firebase Messaging. But its throwing error during refreshIfExpired method call.
private static String getAccessToken() throws IOException {
String[] SCOPES = {"https://www.googleapis.com/auth/firebase.messaging"};
GoogleCredentials googleCredentials = GoogleCredentials.fromStream(new FileInputStream("./src/service-account.json")).createScoped(Arrays.asList(SCOPES));
//googleCredentials.refresh();
try {
googleCredentials.getAuthenticationType();
googleCredentials.refreshIfExpired();
} catch (IOException e) {
e.printStackTrace();
}
return googleCredentials.getAccessToken().getTokenValue();
}
When i remove refreshIfExpired and call getAccessToken directly also same error is coming. Any suggestion. Are these related to jars? As i have uploaded certain jars downloaded from Maven as i do not find anything on google firebase link.
Error at refreshIfExpired step: Error getting access token for service account: Remote host terminated the handshake, iss: firebase-adminsdk-jnf15@***
When I run the function startWeeklyTopPostEmailer()
it has the following problem.
[WARN] PersistentConnection: pc_0 - Provided authentication credentials are invalid. This usually indicates your FirebaseApp instance was not initialized correctly. Make sure your google-services.json file has the correct firebase_url and api_key. You can re-download google-services.json from https://console.firebase.google.com/.
I created the firebase app and created service account key (JSON).
Please let me know if I need to provide more info. Thanks
Hi. Since there is no way to create an issue in the Firebase Admin SDK private repository, I decided that this was the best place to do it (if I am wrong, please, let me know).
The following exception is thrown whenever initializing an app with the same name twice.
java.lang.IllegalStateException: FirebaseApp name {appName} already exists!
I understand one should not initialize the same app twice. But there should be a way to update the app settings/options/credentials/etc.
The class com.google.firebase.FirebaseApp statically maps apps to their names, and there is no way to unmap an app. Internally, the class has a delete method, which probably does what is needed in order to initialize another app using new com.google.firebase.FirebaseOptions using a previous name, but the method is not visible. Extending com.google.firebase.FirebaseApp is not an option either, hence its constructor is private.
The only way to re-create an app is killing the JVM and starting the process again, which frees the static instances from memory. But that implies killing our backend servers aswell.
Please, consider making delete method public if that would solve this issue.
Thanks.
This is more a request, can Google create a role so only read is allowed for a Service Account?
Please see https://stackoverflow.com/questions/48218045/firebase-limited-service-account
Running this on local machine with Java 8
FirebaseOptions options = new FirebaseOptions.Builder() .setCredential(FirebaseCredentials.applicationDefault()) .setDatabaseUrl("https://" + ServiceOptions.getDefaultProjectId() + ".firebaseio.com/") .build();
firebaseDatabase = FirebaseDatabase.getInstance(FirebaseApp.initializeApp(options)); final DatabaseReference entry = firebaseDatabase.getReference("somereference"); entry.setValue("data",(databaseError, databaseReference) -> System.out.println("ok"));
How can i choose to use daemon threads? And if not, why don't you have a shutdown/close option?
I notice that entry.setValue("data") shutdowns threads normally.
you can run this command to generate a gradle wrapper and add the wrapper to the project
gradle wrapper
Enable java admin sdk to sign in users and allow the ability to create ID tokens.
Hello, I am not a developer that does not place an issue, but, at this moment I will do it because I am help with the java-firebase-sdk-admin product, Logre creates the whole project and tests with netbeans and it works perfectly.
Once you place the elements to create a jar compile without problems:
Use this method in the build.gradle to create the jar:
quickstart-java
| --- Database
| - build.gradle
task fatJar (type: Jar) {
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': version,
'Main-Class': 'com.google.firebase.quickstart.Database'
}
baseName = project.name + '-all'
from {configurations.compile.collect {it.isDirectory ()? it: zipTree (it)}}
with jar
}
With the command the command:
$ ./gradkew fatJar
This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.9/userguide/gradle_daemon.html
TIMFJ: database jsilvah $ ./gradlew fatJar
: compileJava
: processResources UP-TO-DATE
: classes
: fatJar
BUILD SUCCESSFUL
When executing it in console:
quickstart-java
| --- Database
| - build
| - libs
$ java -jar database-all-1.0.jar
I got this error:
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState (ZLjava / lang / String; Ljava / lang / Object;) V
at com.google.firebase.FirebaseApp.checkNotDeleted (FirebaseApp.java:317)
at com.google.firebase.FirebaseApp.getOptions (FirebaseApp.java:263)
at com.google.firebase.database.FirebaseDatabase.getInstance (FirebaseDatabase.java:75)
at com.google.firebase.quickstart.Database.init (Database.java:732)
at com.google.firebase.quickstart.Database.main (Database.java:737)
Already after several days trying all kinds of juggling like adding dependency:
compile group: 'com.google.guava', name: 'guava', version: '21 .0 ' or
Update Gradle to the latest version (4.2)
After a huge disappointment I took the time to download the last test of this same place
firebase / quickstart-java
I opened it as a Netbeans project, the test was executed perfectly and with the fatJar I compiled the jar, which creates it without any problem:
This build could be faster, please consider using the Gradle Daemon:
https://docs.gradle.org/2.9/userguide/gradle_daemon.html
TIMFJ: database jsilvah $ ./gradlew fatJar
: compileJava
: processResources UP-TO-DATE
: classes
: fatJar
BUILD SUCCESSFUL
and when executing it
$ java -jar database-all-1.0.jar
I chose the same error:
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState (ZLjava / lang / String; Ljava / lang / Object;) V
at com.google.firebase.FirebaseApp.checkNotDeleted (FirebaseApp.java:317)
at com.google.firebase.FirebaseApp.getOptions (FirebaseApp.java:263)
at com.google.firebase.database.FirebaseDatabase.getInstance (FirebaseDatabase.java:75)
at com.google.firebase.quickstart.Database.init (Database.java:732)
at com.google.firebase.quickstart.Database.main (Database.java:737)
I have the luck that I have Mac (High Sierra), Pc (Windows), Linux (Ubuntu 16) to test in the three operating systems I have java development environments, and in all I had the same result.
Perform compilation tests of the jar with it eliminating all dependencies of the quickstart-java firebase project and place a:
public static void main (String [] args) {
System.out.println ("hello world");
}
compiled and executed without problems:
$ java -jar database-all-1.0.jar
Hello World
I had a lot of confidence in the project but now my project partners are asking me to abandon the firebase-admin-sdk technology.
I am new to firebase however I did setup service account in console and used "messaging.java". Downloaded proper json file and updated all required variables in file.
I am getting this error now for getting access token from GoogleCredentials. I am unable to figure out what am I missing. Is it any variable misisng in my credentials file? or scope?
java.lang.NullPointerException at Messaging.getAccessToken
Can someone please advise? Below is my code:
` private static final String PROJECT_ID = "";
private static final String BASE_URL = "https://fcm.googleapis.com";
private static final String FCM_SEND_ENDPOINT = "/v1/projects/" + PROJECT_ID + "/messages:send";
private static final String MESSAGING_SCOPE = "https://www.googleapis.com/auth/firebase.messaging";
private static final String[] SCOPES = { MESSAGING_SCOPE };
private static final String TITLE = "FCM Notification";
private static final String BODY = "Notification from FCM";
public static final String MESSAGE_KEY = "message";
public static final String FIREBASE_SERVICE_PATH = "firebase_service_account/google-services.json";
/**
Regards
Baljit
I followed this steps to get JSON file :
and run this code :
private static String getAccessToken() throws IOException {
GoogleCredentials googleCredentials = GoogleCredentials
.fromStream(new FileInputStream("service-account.json"))
.createScoped(Arrays.asList(SCOPES));
googleCredentials.refreshAccessToken();
return googleCredentials.getAccessToken().getTokenValue();
}
SCOPES is { "https://www.googleapis.com/auth/firebase.messaging" }
but them throws Exception and the message is Error getting access token for service account: RSA premaster secret error
how could I fix it ?
I was trying to run database example just to see how it works.
I created a desktop server app for my project, and I changed DATABASE_URL with mine and "service-account.json" with my json.
But I got this in the log:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
I visited the link above but got no usable information why this is happening or where it is coming from...
25-04-2020: I checked connecting to database from my android client and it worked just fine. but not on the desktop server.
Hi, I get following error, despite I upgraded to 8.2.2. Error is coming back.
I imported this file in Android Studio Hedgehog | 2023.1.1 Patch 2
I also took out compile and testcompile and replace it with implementation.
Error :
Gradle DSL method not found: 'classpath()'
Possible causes:
Your project may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).
Upgrade plugin to version 8.2.2 and sync project
Open Gradle wrapper file
Apply Gradle plugin
Until yesterday, we could find the Firebase Admin SDK on Maven repository. We can still install it but the GitHub repo has disappeared.
I have an issue with the GSON dependency used by Firebase Admin SDK. It is using GSON version 2.6.2 which has an configuration issue. Please, update it to 2.7.0 or higher if possible.
Also, can I find some news about Firebase Admin Java SDK somewhere? I can't think Firebase team leaving its lovely community in the dark. 🕵️
Just a quick question about the compatibility of the lib with the latest version of Google Guava which led me to some problems when I updated my project to the last one 21.0. A gradle dependencies display an old version required for Firebase. com.google.guava:guava-jdk5:17.0
Also I'm really interested in the Firebase SDK to handle the users management. Do you have any plan to reach NodeJS compatibility ?
Regards to the team
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.