我嘗試在Firebase雲消息傳遞中創建一組設備,並且我收到了一個ioexception「https://android.googleapis.com/gcm/googlenotification」。 我有幾個關於它的問題:Firebase雲消息傳遞 - 一組設備
- 我需要放在字段中:senderId,registrationId,idToken?
- 我如何更改這部分代碼來創建一個組,而不是添加到組?
- 我需要把「授權」,「鑰匙= AIzaS ...」嗎?
代碼:
public String addNotificationKey(
String senderId, String userEmail, String registrationId, String idToken)
throws IOException, JSONException {
URL url = new URL("https://android.googleapis.com/gcm/googlenotification");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setDoOutput(true);
// HTTP request header
con.setRequestProperty("project_id", senderId);
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Accept", "application/json");
con.setRequestMethod("POST");
con.connect();
// HTTP request
JSONObject data = new JSONObject();
data.put("operation", "add");
data.put("notification_key_name", userEmail);
data.put("registration_ids", new JSONArray(Arrays.asList(registrationId)));
data.put("id_token", idToken);
OutputStream os = con.getOutputStream();
os.write(data.toString().getBytes("UTF-8"));
os.close();
// Read the response into a string
InputStream is = con.getInputStream();
String responseString = new Scanner(is, "UTF-8").useDelimiter("\\A").next();
is.close();
// Parse the JSON string and return the notification key
JSONObject response = new JSONObject(responseString);
return response.getString("notification_key");
}
id令牌與註冊令牌有什麼區別? –