11

I have a web Api, which needs to validate purchases from Play Store. According to what I read in the google api documentation, I need to have a service account, and use its credentials to be authenticated, 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();

It throws the following exception

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

I have NO IDEA of what can be causing it. I searched a lot, but I didn't find something really helpful. Any kind help will be really appreciated.

fciancio
  • 115
  • 7
  • I have same problem with test purchases. Url looks like this: https://www.googleapis.com/androidpublisher/v1.1/applications/com.example.app/inapp/exampleSku/purchases/rojeslcdyyiapnqcynkjyyjh?access_token=[your_access_token_here]. Have no idea what is wrong but test purchase. – Swayok Mar 12 '14 at 08:59
  • same here, stuck in the same problem other error though – itay83 Mar 17 '14 at 10:06
  • If your error is forbidden, the solution is here : http://stackoverflow.com/questions/22471433/service-account-403-forbidden-google-play-in-app-billing-purchase-status-api – rouen Apr 30 '14 at 07:52

1 Answers1

5

I know this question is "a little" old, but I still want to try to answer for clarification.

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

My guess would be that this part is not entirely right. The Purchases class does not have a Get method. Before that you have to specify either (in your case): service.Purchases.Products.Get(...) -> for consumable products

service.Purchases.Subscriptions.Get(...) -> for subscriptions

This answer assumes you are using V2. Hope it helps anyone who is stuck.

MattJ
  • 683
  • 2
  • 10
  • 35