火云消息传递异常:java.io.FileNotFoundException:https://fcm.googleapis.com/v1/projects/firebase-*****

时间:2019-03-20 22:28:36

标签: android firebase firebase-cloud-messaging

我是FCM的新手,我尝试以编程方式将通知发送到我的android设备。我尝试这段代码

    URL url = new URL("https://fcm.googleapis.com/v1/projects/firebase-********@fir-message-******.gserviceaccount.com/messages:send");
                HttpURLConnection con = (HttpURLConnection) url.openConnection();
                con.setDoOutput(true);
                // HTTP request header                 
                con.setRequestProperty("Content-Type", "application/json");                 
                con.setRequestProperty("Authorization","Bearer "+"AAAA6FyfxIw:************************");
                //con.setRequestMethod("POST");
                con.connect();
                //
                // HTTP request
                JSONObject data = new JSONObject();
                JSONObject content = new JSONObject();
                data.put("to", FirebaseInstanceId.getInstance().getToken());
                data.put("data","Hi Bahaa!");
                data.put("operation", "create");
                data.put("notification_key_name","bahaa@gmail.com");
                data.put("registration_ids", FirebaseInstanceId.getInstance().getToken());

                //Send request
                DataOutputStream wr = new DataOutputStream (con.getOutputStream());
                wr.write(data.toString().getBytes("UTF-8"));
                wr.close();
                //Get Response

                InputStream is = con.getInputStream();//Exception is here
                BufferedReader rd = new BufferedReader(new InputStreamReader(is));
                StringBuilder response = new StringBuilder(); // or StringBuffer if Java version 5+
                String line;
                while ((line = rd.readLine()) != null) {
                    response.append(line);
                    response.append('\r');
                }
                rd.close();
                Log.i("response", response.toString());

但是它总是给我“ java.io.FileNotFoundException:https://fcm.googleapis.com/v1/projects/firebase- ******** @ fir-message-******。gserviceaccount.com/messages:send”

我错过了什么?

0 个答案:

没有答案