Last active
October 9, 2022 12:58
-
-
Save hiranya911/66aad2db5216fda6b2a4284c69685881 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.auth.oauth2.GoogleCredentials; | |
import com.google.cloud.firestore.DocumentSnapshot; | |
import com.google.cloud.firestore.Firestore; | |
import com.google.firebase.FirebaseApp; | |
import com.google.firebase.FirebaseOptions; | |
import com.google.firebase.messaging.FirebaseMessaging; | |
import com.google.firebase.messaging.Message; | |
import com.google.firebase.messaging.Notification; | |
public class Main { | |
public static void main(String[] args) throws Exception { | |
System.setProperty("https.proxyHost", "localhost"); | |
System.setProperty("https.proxyPort", "3128"); | |
System.setProperty("com.google.api.client.should_use_proxy", "true"); | |
FirebaseOptions options = | |
FirebaseOptions.builder() | |
.setCredentials(GoogleCredentials.getApplicationDefault()) | |
.build(); | |
FirebaseApp.initializeApp(options); | |
Firestore firestore = FirestoreClient.getFirestore(); | |
DocumentSnapshot snapshot = firestore.collection("users").document("alice").get().get(); | |
FirebaseMessaging messaging = FirebaseMessaging.getInstance(); | |
String response = messaging.send(Message.builder() | |
.setTopic(snapshot.getString("topicName")) | |
.setNotification(new Notification( | |
"Hello from the other side", | |
"I must have called this proxy a thousand times")) | |
.build()); | |
System.out.println(response); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment