本文介绍了我是否得到了正确的步骤来检查用户的Android的应用内订阅?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我提出一个应用程序,不需要一个用户帐户/登录,并允许用户购买订阅。我想使用谷歌Play开发的API来验证用户是否有购买/积极认购。从所有的文档,我已经收集了以下步骤。I am making an app that does not require a user account/login, and allows the user to purchase a subscription. I want to use the Google Play Developer API to verify whether or not a user has a purchased/active subscription. From all of the documentation, I've gathered the following steps.他们是正确的,而你能在他们回答这两个问题?Are they correct, and could you answer the two questions in them?创建一个服务帐户在谷歌API控制台的。保存的是给我(这里肯定不是我的code /设备作为的 此示例code 建议)使用谷歌的API客户端库的Java 创建并签署智威汤逊用私钥(怎么样? 的文档给我这个 ,但它不是Java code。 ..我该怎么办呢?)在构建一个访问令牌请求,并获得访问API应用程序现在可以发送请求GET 的API,以找出是否与否用户订阅当访问令牌期满,回到步骤3。Create a Service Account in the Google APIs Console.Save the private key that is given to me (where? surely not in my code/on the device as this sample code suggests)Use Google APIs Client Library for Java to create and sign a JWT with the private key (how? the docs give me this, but that is not Java code... What do I do with it?)Construct an access token request, and get access to the APIApplication can now send a GET request to the API to find out whether or not theuser has a subscriptionWhen the access token expires, go back to step 3.另外,我有一个Web服务,虽然我什么都不知道的Web服务或Web服务编程......我只知道足够的注意,它可能需要在这里使用。Also, I have a web service, though I know nothing about web services or web service programming... I only know enough to be aware that it is probably necessary to use here. 编辑:这些步骤都是不正确的。请参阅下面的正确步骤,我的答案。但是,请注意,这仅适用于使用服务帐户(因为我不想要求用户必须明确允许API访问)推荐答案事实证明,我的步骤是不正确的。我花了几个星期摸不着头脑,它似乎并没有被记录在其他地方。不客气:As it turns out, my steps were not correct. It took me weeks to figure this out and it doesn't seem to be documented anywhere else. You're welcome: 创建一个 Web应用程序帐户中谷歌API控制台。把任何网站作为一个重定向URI;没关系,因为你不会真的使用它。你会得到一个客户ID和客户端密钥,当您创建帐户。Create a Web Application account in the Google APIs Console. Put any website as a "redirect URI"; it doesn't matter since you will not really be using it. You will get a client id and client secret when you create the account.在您的计算机上的浏览器去https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/androidpublisher&response_type=$c$c&access_type=offline&redirect_uri=[YOUR REDIRECT URI]放大器;当出现提示时CLIENT_ID = [您的客户端ID] ,并允许访问In a browser on your computer go to https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/androidpublisher&response_type=code&access_type=offline&redirect_uri=[YOUR REDIRECT URI]&client_id=[YOUR CLIENT ID] and allow access when prompted.看在地址栏。在URI结束时,您输入的本来将是你的刷新令牌。它看起来像 1 /....您将需要在接下来的步骤中,该code。刷新令牌永不过期。Look in the address bar. At the end of the URI you entered originally will be your refresh token. It looks like 1/.... You will need this "code" in the next step. The refresh token never expires.转到 https://accounts.google.com/o/oauth2/token?client_id= [你的客户转换这种code到刷新令牌 ID]放大器; client_secret = [您的客户端秘密]放; code = [code从preVIOUS STEP]放大器; grant_type = authorization_ code和; redirect_uri = [您的重定向URI] 。您可以保存所产生的价值就在你的程序;它永远不会过期,除非明确撤销。 (这一步@BrianWhite插入 - 看评论的)Convert this "code" to a "refresh token" by going to https://accounts.google.com/o/oauth2/token?client_id=[YOUR CLIENT ID]&client_secret=[YOUR CLIENT SECRET]&code=[CODE FROM PREVIOUS STEP]&grant_type=authorization_code&redirect_uri=[YOUR REDIRECT URI]. You can save the resulting value right in your program; it never expires unless explicitly revoked. (this step inserted by @BrianWhite -- see comments)在你的code,发送与BasicNameValuePairs一个HttpPost请求 https://accounts.google.com/o/oauth2/token grant_type,refresh_token,CLIENT_ID,[你的客户ID] , client_secret,[你的客户的秘密] ,refresh_token,[你刷新令牌] 。举个例子看看这里。你需要做一个单独的线程,可能使用AsyncTask的。这将返回一个JSONObject的。In your code, send an HttpPost request to https://accounts.google.com/o/oauth2/token with the BasicNameValuePairs "grant_type","refresh_token", "client_id",[YOUR CLIENT ID], "client_secret",[YOUR CLIENT SECRET], "refresh_token",[YOUR REFRESH TOKEN]. For an example look here. You will need to do this in a separate thread, probably using AsyncTask. This will return a JSONObject.获取从返回的JSONObject的访问令牌。举个例子看看这里。您将需要得到字符串access_token。访问令牌到期在1小时内。Get the access token from the returned JSONObject. For an example look here. You will need to get the string "access_token". The access token expires in 1 hour.在你的code,发送HTTPGET请求 https://www.googleapis.com/androidpublisher/v1/applications/ [您的应用程序包装名称] /订阅/ [作者:发布的认购从Android开发者控制台中的id] /采购/ [消费者购买令牌用户收到致函购买认购] accesstoken =[访问令牌步骤4]。举一个例子看here.In your code, send an HttpGet request to https://www.googleapis.com/androidpublisher/v1/applications/[YOUR APP'S PACKAGE NAME]/subscriptions/[THE ID OF YOUR PUBLISHED SUBSCRIPTION FROM YOUR ANDROID DEVELOPER CONSOLE]/purchases/[THE PURCHASE TOKEN THE USER RECEIVES UPON PURCHASING THE SUBSCRIPTION]?accesstoken="[THE ACCESS TOKEN FROM STEP 4]". For an example look here. 这篇关于我是否得到了正确的步骤来检查用户的Android的应用内订阅?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!