I need to validate my google play purchases using the PurchaseStatus API.. i want to use the AccountService option... [I did get this to work using the WebServer workflow, but that requires manual interaction, i can't use that on production ]. For using Service Account, I tried two approaches that i could think of:
1) Token using Google Libraries + REST APIs..
credential = new ServiceAccountCredential( new ServiceAccountCredential.Initializer(serviceAccountEmail)
{ Scopes = new[] { "https://www.googleapis.com/auth/androidpublisher" }
}.FromCertificate(certificate));
var task = credential.RequestAccessTokenAsync(cancellationtoken);
// wait for it ... with error handling..
var accessToken = credential.Token.AccessToken ;
string url = string.Format("https://www.googleapis.com/androidpublisher/v1.1/applications/{0}/inapp/{1}/purchases/{2}?access_token={3}", packageName, sku, purchaseToken , accessToken );
// UseWebRequest agains that URL ...
RESULT: the above fails with 401: Unauthorized
That same code, works OK if instead of using the token coming from ServiceAccountCredential, I use a token from Web Server workflow..
2) Next I tried using ServiceAccountCredential + AndroidPublisherService.. so both google libraries:
// Same ServiceAccountCredential as above.. but now I initialize my AndroidPublisherService with the credential in this manner..
AndroidPublisherService svc = new AndroidPublisherService( new Google.Apis.Services.BaseClientService.Initializer()
{ HttpClientInitializer = credential });
var purchaseRequest = svc.Inapppurchases.Get(packageName, sku, token);
var purchase = purchaseRequest.Execute();
RESULT: I get a
[Google.GoogleApiException]
{"Google.Apis.Requests.RequestError\r\nThis developer account does not own the application. [401]\r\nErrors [\r\n\tMessage[This developer account does not own the application.] Location[ - ] Reason[developerDoesNotOwnApplication] Domain[androidpublisher]\r\n]\r\n"} Google.GoogleApiException
3) I tried a few other things such as trying to pass a User to the initializer... but they did not work..
What am I doing wrong?
How can I validate an Android Purchase using the ServiceAccount
from ASP .NET ?