Где взять зависимости Scopes для Java для нового API Firebase Cloud Message?

2

FCM Api был обновлен до версии v1, и теперь u не может передать key=<API_KEY> (однажды сгенерированный из консоли FCM), как и раньше, теперь вы должны сгенерировать его с помощью SDK com.google.api-client и там вы должны пройти тайну SCOPES внутри createScoped(). Здесь много примеров - без информации о областях. Но что это? где его получить? Я не могу найти никакой информации об этом. пожалуйста, помогите мне

Теги:
firebase-cloud-messaging
push

3 ответа

1

Этот способ получения токена доступа не работает, я попробовал. Но вы можете попробовать прямой 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);
    }
}

}

  • 0
    Это старый API (скоро будет унаследован), я пытался использовать v1 API
0

Область - это список строк. Я пробовал несколько конечных точек из https://developers.google.com/identity/protocols/googlescopes и работал.

  1. " https://www.googleapis.com/auth/firebase "
  2. " https://www.googleapis.com/auth/cloud-platform "
  3. 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
    
0

Область полномочий - это список, который я нашел на странице. Сначала я не мог понять, для чего они нужны, но потом я догадался

https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages/send

  • 1
    Пожалуйста, включите соответствующие части по ссылке здесь

Ещё вопросы

Сообщество Overcoder
Наверх
Меню