Aide à la migration firebase FCM ver HTTP v1
CR16_Padawan
Messages postés
58
Date d'inscription
mercredi 7 juin 2023
Statut
Membre
Dernière intervention
11 septembre 2024
-
23 août 2024 à 16:03
CR16_Padawan Messages postés 58 Date d'inscription mercredi 7 juin 2023 Statut Membre Dernière intervention 11 septembre 2024 - 11 sept. 2024 à 20:11
CR16_Padawan Messages postés 58 Date d'inscription mercredi 7 juin 2023 Statut Membre Dernière intervention 11 septembre 2024 - 11 sept. 2024 à 20:11
A voir également:
- Aide à la migration firebase FCM ver HTTP v1
- Migration windows 7 vers windows 10 - Guide
- Protocole http - Guide
- Http error 413 zimbra - Forum autres boîtes mail
- Http //zh.ui.vmall.com/emotiondownload.php mod=restore - Forum Huawei
- Http //my.canalbox.africa ✓ - Forum Box et Streaming vidéo
1 réponse
CR16_Padawan
Messages postés
58
Date d'inscription
mercredi 7 juin 2023
Statut
Membre
Dernière intervention
11 septembre 2024
11 sept. 2024 à 20:11
11 sept. 2024 à 20:11
bonjour,
bon, après beaucoup de tentatives j'ai obtenu ce code:
public void sendPushNotification(String fcmToken, String title, String body, String accessToken) { try { URL url = new URL("https://fcm.googleapis.com/fcm/send"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("Authorization", "Bearer " + accessToken); conn.setRequestProperty("Content-Type", "application/json"); conn.setDoOutput(true); JSONObject message = new JSONObject(); message.put("to", fcmToken); JSONObject notification = new JSONObject(); notification.put("title", title); notification.put("body", body); message.put("notification", notification); OutputStream os = conn.getOutputStream(); os.write(message.toString().getBytes("UTF-8")); os.close(); InputStream is = conn.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String response; StringBuilder sb = new StringBuilder(); while ((response = br.readLine()) != null) { sb.append(response); } br.close(); Log.d("FCM", "Response: " + sb.toString()); } catch (Exception e) { Log.e("FCM", "Error sending push notification", e); } }
toutefois pour l'essayer il me faut le jeton d'accès (accessToken) et je n'arrive pas à l'obtenir.
Si quelqu'un a une idée?
cordialement