【问题标题】:Validating google play purchases using Purchase Status API使用购买状态 API 验证 google play 购买
【发布时间】: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


    【解决方案1】:

    请按照这篇 SO 文章中的步骤进行操作-Am I getting the steps right for verifying a user's Android in-app subscription?

    简而言之,您需要在 Google API 控制台上创建应用程序并使用客户端 ID 和客户端密码。

    然后,您需要获得一个永不过期的“刷新令牌”,并且可以保存在应用程序中以供将来所有请求使用。

    刷新令牌后,您需要发出一个发布请求,该请求将使用该令牌提供一个“访问令牌”,您可以发送一个获取请求并验证购买。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-21
      • 1970-01-01
      • 2020-04-08
      • 2017-10-03
      • 1970-01-01
      • 2019-09-11
      • 1970-01-01
      相关资源
      最近更新 更多