I'm trying to submit a new print job to Google Cloud Print from an App Engine app (Java).
In the Google Cloud Print settings for the printer, I set "can print" permissions to {{MY_APP_ID}}@appspot.gserviceaccount.com
Then, from the App Engine app I run the following code-
AppIdentityCredential credential = new AppIdentityCredential(
Arrays.asList("https://www.googleapis.com/auth/cloudprint"));
HttpRequestFactory requestFactory =
new UrlFetchTransport().createRequestFactory(credential);
Map<String, String> params = new LinkedHashMap<String, String>();
params.put("printerid", "{{PRINTER_ID}}");
params.put("title", "Title");
params.put("ticket", "{\"version\":\"1.0\", \"print\":{}}");
params.put("content", "<!DOCTYPE html>\n<html>\n<body>\nHello world!\n</body>\n</html>");
params.put("contentType", "text/html");
HttpRequest httpRequest = requestFactory.buildPostRequest(
new GenericUrl("https://www.google.com/cloudprint/submit"),
new UrlEncodedContent(params));
HttpResponse httpResponse = httpRequest.execute();
try {
System.out.println(httpResponse.parseAsString());
} finally {
httpResponse.ignore();
}
Google Cloud Print's API returns a response with success=false and message="User is not authorized."
However, it seems that it does recognize the correct user as the response's users field is indeed ["{{MY_APP_ID}}@appspot.gserviceaccount.com"].
What am I doing wrong? Is there any way to have an App Engine app print to Google Cloud Print with the app's own permissions?