小编Tim*_*thy的帖子

firebase(fcm)说401未经授权

private void sendMsg() {
    DBManager dbManager = DBManager.getInstance();
    ArrayList<String> firebaseIds;

    try {
        ResultSet rs= dbManager.getRegisteredFirebaseDevice();
        while(rs.next()){
            System.out.println(rs.getString(1));
            firebaseIds.add(rs.getString(1));
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }

    String url = "https://fcm.googleapis.com/fcm/send";
    URL obj = new URL(url);
    HttpURLConnection con = (HttpURLConnection) obj.openConnection();

    // add reuqest header
    con.setRequestMethod("POST");
    con.setRequestProperty("Authorization: key", "AIzaSyAl6S936qt_NKKFwwbd-NEmiSGIL7G_yJc");
    con.setRequestProperty("Content-Type", "application/json");
    // String msg="New design added in "+getCategory(designCategory)+". Design no."+designNo;
    // String urlParameters = "data.msg="+msg+"&registration_id="+firebaseIds.get(0);

    JSONObject msg=new JSONObject();
    msg.put("msg","New design added in "+getCategory(designCategory)+". Design no."+designNo);


    JSONObject parent=new JSONObject();

    parent.put("to", firebaseIds.get(0));
    parent.put("data", …
Run Code Online (Sandbox Code Playgroud)

android java-ee firebase firebase-authentication firebase-cloud-messaging

6
推荐指数
2
解决办法
1万
查看次数