title: How to validate in-app-purchase Android server side Java?
body: <p>I followed this tutorial: <a href="https://medium.com/@infinitesimal_/doing-android-purchase-validation-api-v3-in-java-5c46fc837368" rel="noreferrer">https://medium.com/@infinitesimal_/doing-android-purchase-validation-api-v3-in-java-5c46fc837368</a></p>
  
  <p>But I can not make it work! All I can get is this: </p>
  
  <pre><code>{
    "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."
  }
  </code></pre>
  
  <p>This is my java code: </p>
  
  <pre><code>    HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();    
  
      JacksonFactory jsonFactory = JacksonFactory.getDefaultInstance();        
      String applicationName = "My App";       
      String packageName = "com.my.package";
      final Set&lt;String&gt; 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());
  </code></pre>
  
  <p>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.</p>