title: Get 403 response with the "new" Firebase Cloud Messaging API
body: <p>We are successfully using the <a href="https://firebase.google.com/docs/cloud-messaging/http-server-ref" rel="noreferrer">Legacy HTTP Server Protocol</a> on our server for FCM.
  I wanted to update to <a href="https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages" rel="noreferrer">FCM HTTP v1 API</a> today.</p>
  
  <p>I did it <a href="https://firebase.google.com/docs/cloud-messaging/auth-server" rel="noreferrer">step by step</a> and when the server calls the request, we get this response: </p>
  
  <pre><code>Server returned HTTP response code: 403 for URL: https://fcm.googleapis.com/v1/projects/[projectid]/messages:send
  </code></pre>
  
  <p>This is the server code:</p>
  
  <pre><code>URL url = new URL("https://fcm.googleapis.com/v1/projects/[projectid]/messages:send");
  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  conn.setRequestProperty("Authorization", "Bearer " + getAccessToken());
  conn.setRequestProperty("Content-Type", "application/json");
  OutputStream outputStream = conn.getOutputStream();
  outputStream.write(req.getBytes("UTF-8"));
  
  // Exception happen here
  InputStream inputStream = conn.getInputStream();
  </code></pre>
  
  <p>The getAccessToken():</p>
  
  <pre><code>private static String getAccessToken() throws IOException {
          GoogleCredential googleCredential = GoogleCredential
              .fromStream(new FileInputStream(ClientApiServlet.context.getRealPath("/WEB-INF/[projectid].json")))         .createScoped(Arrays.asList("https://www.googleapis.com/auth/firebase.messaging"));
          googleCredential.refreshToken();
          return googleCredential.getAccessToken();
  }
  </code></pre>
  
  <p>I have downloaded the json file from the adminsdk page of the firebase cloud.</p>
  
  <p>All with the same projectid...</p>
  
  <p>I updated these 2 libs on the server:</p>
  
  <pre><code>google-http-client-jackson2-1.23.0.jar
  google-oauth-client-1.23.0.jar
  </code></pre>
  
  <p>The getAccessToken() methode returned an accesstoken: "ya29.c.Elr0BAa..."</p>
  
  <p>I think, I miss a small step, maybe you could help?
  Thanks in advance!</p>
  
  <p><strong>Edit:</strong>
  It is working now with the hint of <strong>arterpa</strong>! Thanks again!</p>
  
  <p>After that I got a 400 error, so something in the request data was wrong:</p>
  
  <p>The problem was, we didn't converted all <code>data{...}</code>values to strings. With the legacy protocol it was not an issue, but with FCM HTTP v1 API it has to be strings! ;)</p>