从哪里获取新 Firebase Cloud Message API 的 java 范围依赖项?

Where to get Scopes dependencies for java for new Firebase Cloud Message API?

FCM Api 已更新到 v1,现在您无法像以前一样通过 key=<API_KEY>(从 FCM 控制台生成)header,现在您应该通过 SDK 生成它com.google.api-client 并且你应该在 createScoped() 方法中传递神秘的 SCOPES。 Here 有很多关于它的例子——没有关于范围的信息。但这是什么?从哪里得到它?我找不到任何关于它的信息。请帮助我

这种获取访问令牌的方式无效我tried.But你可以尝试直接 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://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages/send

范围是字符串列表。我已经尝试了 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