从何处获取新Firebase云消息API的java范围依赖项?
FCMAPI被更新为v1,现在你不能传递很多关于它的例子,没有关于作用域的信息。但这是什么?在哪里可以买到?我找不到关于它的任何信息。请帮助我我尝试过的这种获取访问令牌的方法不起作用。但是你可以尝试直接http请求从何处获取新Firebase云消息API的java范围依赖项?,java,api,push,firebase-cloud-messaging,Java,Api,Push,Firebase Cloud Messaging,FCMAPI被更新为v1,现在你不能传递很多关于它的例子,没有关于作用域的信息。但这是什么?在哪里可以买到?我找不到关于它的任何信息。请帮助我我尝试过的这种获取访问令牌的方法不起作用。但是你可以尝试直接http请求 public static void main(String args[]) throws IOException { public final static String AUTH_KEY_FCM = "server key"; public
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);
}
}
}授权范围是我在页面上找到的列表。起初我不明白它们是干什么用的,但后来我猜到了
范围是字符串列表。我已经尝试了来自的多个端点,并且成功了
作用域自:为了授权访问FCM,请求作用域无效这是一个旧API(将很快遗留下来),我尝试使用v1 API。请包括链接中的相关部分。作用域是字符串列表。[ "", "", "" ]
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