Friday, 1 February 2019

How to validate in-app-purchase Android server side Java?

I followed this tutorial: https://medium.com/@infinitesimal_/doing-android-purchase-validation-api-v3-in-java-5c46fc837368

But I can not make it work! All I can get is this:

{
  "code" : 401,
  "errors" : [ {
    "domain" : "androidpublisher",
    "message" : "The current user has insufficient permissions to perform the requested operation.",
    "reason" : "permissionDenied"
  } ],
  "message" : "The current user has insufficient permissions to perform the requested operation."
}

This is my java code:

    HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();    

    JacksonFactory jsonFactory = JacksonFactory.getDefaultInstance();        
    String applicationName = "My App";       
    String packageName = "com.my.package";
    final Set<String> scopes = Collections.singleton(AndroidPublisherScopes.ANDROIDPUBLISHER);
    GoogleCredential credential = new GoogleCredential.Builder()                    
        .setTransport(httpTransport)                        
        .setJsonFactory(jsonFactory)                    
        .setServiceAccountId("myAccoutId")                     
        .setServiceAccountScopes(scopes)                    
        .setServiceAccountPrivateKeyFromP12File(
          new File("/my/path"))                    
        .build();

    AndroidPublisher pub = new AndroidPublisher.Builder
            (httpTransport, jsonFactory, credential)                     
            .setApplicationName(applicationName)                    
            .build();            
        final AndroidPublisher.Purchases.Products.Get get = 
            pub.purchases()
            .products()                    
            .get(packageName, "name", "transactionId"); 
        final ProductPurchase purchase = get.execute();            
        System.out.println("Found google purchase item " + purchase.toPrettyString());

I created a service account and gave the owner role. I went to the Google play console, and in Users and Permissions I also let this service account as administrator.



from How to validate in-app-purchase Android server side Java?

No comments:

Post a Comment