I am trying to use the Google Play Custom App Publishing API with a Java client and a service account created from a GCP account of the same user. Despite using the sample code provided in the documentation, I am encountering the following error:
java.io.IOException: insufficient data written
The Cloud Console metrics show that I am receiving a 401 Unauthorized response. Here is a screenshot of the metrics: [attach screenshot].
Below is a snippet of my example application code:
Logger httpLogger = Logger.getLogger("com.google.gdata.client.http.HttpGDataRequest");
httpLogger.setLevel(Level.ALL);
Logger xmlLogger = Logger.getLogger("com.google.gdata.util.XmlParser");
xmlLogger.setLevel(Level.ALL);
// Create a log handler which prints all log events to the console.
ConsoleHandler logHandler = new ConsoleHandler();
logHandler.setLevel(Level.ALL);
httpLogger.addHandler(logHandler);
xmlLogger.addHandler (logHandler);
GoogleCredentials credentials = GoogleCredentials.fromStream(new FileInputStream("/Users/baris/Downloads/customapppublishing-425511-41dddf09fcc3.json"))
.createScoped(PlaycustomappScopes.all());
credentials.refreshIfExpired();
System.out.println(credentials.getAccessToken());
Path apkPath = Paths.get("/Users/baris/Downloads/app-release.apk");
ByteArrayContent apk =
new ByteArrayContent("application/vnd.android.package-archive", Files.readAllBytes(apkPath));
CustomApp appMetadata =
new CustomApp()
.setTitle("P2")
.setLanguageCode("en_US")
.setOrganizations(List.of(new Organization().setOrganizationId("LC02i4l30r")));
Playcustomapp apiClient = new Playcustomapp(GoogleNetHttpTransport.newTrustedTransport(), new JacksonFactory(), new HttpCredentialsAdapter(credentials));
try{
CustomApps.Create request =
apiClient.accounts() // Playcustomapp apiClient
.customApps()
.create(4796812269188016197l, appMetadata, apk);
request.setUploadType("multipart");
CustomApp response = request.execute();
System.out.println(response);
System.out.println(request.getAccount());
} catch (Exception e) {
System.out.println(e);
return "App upload failed";
}
return "App uploaded successfully";
I am using the latest version of the google-api-services-playcustomapp library (v1-rev20211022-2.0.0) and the authentication library (google-auth-library-oauth2-http 1.19.0).
Things I have checked so far:
The service account has the necessary permissions.
The JWT token is correctly generated and signed.
The Google Play Custom App Publishing API is enabled in the GCP project.
Despite these checks, I am still encountering the error. Any guidance on what might be causing the 401 response and how to resolve it would be greatly appreciated.