【发布时间】:2014-03-25 13:04:52
【问题描述】:
我需要使用 PurchaseStatus API 验证我的 google play 购买。我想使用 AccountService 选项... [我确实使用 WebServer 工作流程让它工作,但这需要手动交互,我不能在生产中使用它]。 对于使用服务帐户,我尝试了两种我能想到的方法:
1) 使用 Google 库 + REST API 的令牌..
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 ...
结果:以上失败,401: Unauthorized
如果我不使用来自 ServiceAccountCredential 的令牌,而是使用来自 Web 服务器工作流的令牌,则相同的代码可以正常工作。..
2) 接下来我尝试使用 ServiceAccountCredential + AndroidPublisherService.. 所以这两个谷歌库:
// 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();
结果:我得到一个
[Google.GoogleApiException]
{"Google.Apis.Requests.RequestError\r\n此开发者帐户没有 拥有应用程序。 [401]\r\n错误 [\r\n\tMessage[此开发人员 帐户不拥有该应用程序。] 位置[ - ] 原因[developerDoesNotOwnApplication] 域[androidpublisher]\r\n]\r\n"} Google.GoogleApiException
3) 我尝试了其他一些方法,例如尝试将用户传递给初始化程序......但它们没有工作......
我做错了什么?
如何使用 ASP .NET 中的 ServiceAccount 验证 Android 购买?
【问题讨论】:
标签: android in-app-purchase google-play google-api-dotnet-client