FCM Api был обновлен до версии v1, и теперь u не может передать key=<API_KEY>
(однажды сгенерированный из консоли FCM), как и раньше, теперь вы должны сгенерировать его с помощью SDK com.google.api-client
и там вы должны пройти тайну SCOPES внутри createScoped()
. Здесь много примеров - без информации о областях. Но что это? где его получить? Я не могу найти никакой информации об этом. пожалуйста, помогите мне
Этот способ получения токена доступа не работает, я попробовал. Но вы можете попробовать прямой HTTP-запрос.
public static void main(String args[]) throws IOException {
public final static String AUTH_KEY_FCM = "server key";
public final static String API_URL_FCM =
"https://fcm.googleapis.com/fcm/send";
// Method to send Notifications from server to client end.
// userDeviceIdKey is the device id you will query from your database
String authKey = AUTH_KEY_FCM; // You FCM AUTH key
String FMCurl = API_URL_FCM;
URL url = new URL(FMCurl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setUseCaches(false);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Authorization", "key=" + authKey);
conn.setRequestProperty("Content-Type", "application/json");
JSONObject json = new JSONObject();
json.put("to",
"Device key");
JSONObject info = new JSONObject();
info.put("title", "Demo"); // Notification title
info.put("body", "Hello Test notification"); // Notification body
json.put("notification", info);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(json.toString());
wr.flush();
conn.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
}
}
}
Область - это список строк. Я пробовал несколько конечных точек из https://developers.google.com/identity/protocols/googlescopes и работал.
https://www.googleapis.com/auth/firebase.readonly "
val googleCredential = GoogleCredential.fromStream("yourjson.json")
.createScoped(Arrays.asList("https://www.googleapis.com/auth/firebase",
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/firebase.readonly"))
googleCredential.refreshToken()
return googleCredential.accessToken
Область полномочий - это список, который я нашел на странице. Сначала я не мог понять, для чего они нужны, но потом я догадался
https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages/send