Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Google Play Custom App Publishing API 401 Error

I am trying to use the Google Play Custom App Publishing API with a Java and C# 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 in java:

java.io.IOException: insufficient data written

Also I am getting error below in C#

The service playcustomapp has thrown an exception. HttpStatusCode is Unauthorized. Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.

The Cloud Console metrics show that I am receiving a 401 Unauthorized response. Here is a screenshot of the metrics:

Ekran Resmi 2024-06-07 16.38.31.png

In documentation it is specified that, service account is sufficient for authorization but in error code I am seeing OAuth errors.

 

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.

0 0 513
0 REPLIES 0