2017-11-16 9 views
0

FCM Api가 v1로 업데이트되었으므로 이제 key=<API_KEY> (FCM 콘솔에서 생성됨) 헤더를 이전과 같이 전달할 수 없습니다. 이제 SDK com.google.api-client에 의해 생성해야하며 createScoped() 방법 안에 신비 범위를 전달해야합니다. Here은 스코프에 대한 정보가없는 많은 예제입니다. 그러나 이것은 무엇입니까? 어디서 구할 수 있을까요? 그것에 관한 어떤 정보도 찾을 수 없습니다. 도와주세요새로운 Firebase Cloud Message API에 대한 Java의 범위 종속성은 어디에서 얻을 수 있습니까?

+0

범위를 추측 = 0) : __ FCM에 대한 액세스 권한을 부여하려면 범위 https://www.googleapis.com/auth/firebase.messaging__이 (가) INVALID –

답변

1

액세스 토큰을 얻는 방법이 작동하지 않습니다. 시도했지만 직접 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); 
    } 
} 

}

+0

에 요청합니다.이 API는 오래된 API이므로 곧 v1 API를 사용하려고했습니다. –