An error occurred while trying to get purchases from the Android Publisher service in the .NET web interface.

I have a web api that needs to check purchases on the Play Store. According to what I read in the google api documentation, I need to have a service account and use its credentials for authentication in order to be able to do what I want. I have the following code:

String serviceAccountEmail = "MYSERVICEACCOUNTEMAIL@developer.gserviceaccount.com"; var certificate = new X509Certificate2(@"C:\privatekey.p12", "notasecret", X509KeyStorageFlags.Exportable); ServiceAccountCredential credential = new ServiceAccountCredential( new ServiceAccountCredential.Initializer(serviceAccountEmail) { Scopes = new[] { "https://www.googleapis.com/auth/androidpublisher" } }.FromCertificate(certificate)); // Create the service. var service = new AndroidPublisherService(new BaseClientService.Initializer() { HttpClientInitializer = credential }); var data = service.Purchases.Get("MYPACKAGE", "MYPRODUCT", "MYTOKEN") .Execute(); 

Throws the following exception

 Google.Apis.Requests.RequestError Invalid Value [400] Errors [ Message[Invalid Value] Location[ - ] Reason[invalid] Domain[global] ] 

I have no IDEA for what might be causing this. I searched a lot, but I did not find anything useful. Any help would be really appreciated.

+8
google-play google-api
source share
1 answer

I know this question is a bit old, but I still want to try to answer for clarifications.

 var data = service.Purchases.Get("MYPACKAGE", "MYPRODUCT", "MYTOKEN") .Execute(); 

I assume that this part is not entirely correct. The Purchases class does not have a Get method. Before that, you need to specify either (in your case): service.Purchases.Products.Get(...) → for supplies

service.Purchases.Subscriptions.Get(...) → for subscription

This answer assumes that you are using V2. Hope this helps anyone stuck.

+3
source share

All Articles