错误 400 错误请求 - 无效的 grant_type,当调用 google play 开发者 API 以在 android 中获取订阅详细信息时

我正在尝试使用 google play 开发者 API 读取订阅详细信息,但我看到了一个有趣的行为。通过 Android Studio(作为 Debug 变体)运行我的应用程序时,我能够下载对象。当我创建签名 APK(或作为发布变体运行)时,我无法再使用 google play 开发者 API 下载订阅详细信息并收到 400 错误请求 - 无效的 grant_type。

这是我的授权方式:

   try{
        HttpTransport httpTransport = null;
        httpTransport = new com.google.api.client.http.javanet.NetHttpTransport();

        JacksonFactory jsonFactory = JacksonFactory.getDefaultInstance();

        String applicationName = VariantConstants.AppName;
        String packageName = VariantConstants.packageName;

        final Set<String> scopes = Collections.singleton(AndroidPublisherScopes.ANDROIDPUBLISHER);

        AssetManager am = context.getassets();
        InputStream inputStream = am.open("key.p12");


        if(inputStream != null){
            int SDK_INT = android.os.Build.VERSION.SDK_INT;
            if (SDK_INT > 8) {
                StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
                        .permitAll().build();
                StrictMode.setThreadPolicy(policy);


                GoogleCredential credential = new GoogleCredential.Builder()
                        .setTransport(httpTransport)
                        .setJsonFactory(jsonFactory)
                        .setServiceaccountId("service email")
                        .setServiceaccountScopes(scopes)
                        .setServiceaccountPrivateKeyFromP12File(inputStream)
                        .build();

               

                AndroidPublisher pub = new AndroidPublisher.Builder
                        (httpTransport,jsonFactory,credential)
                        .setapplicationName(applicationName)
                        .build();

              
                final AndroidPublisher.Purchases.Subscriptions.Get get =
                        pub.purchases().subscriptions().get(packageName,VariantConstants.ONE_WEEK_SUB,subscriptionDetail.getPurchaseToken());

             
                final SubscriptionPurchase purchase = get.execute();
             
                return purchase;
            }
        }else{
            System.out.println("input Stream is null.");
        }
    }
   /* catch (GeneralSecurityException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } */
   catch(Exception e){
       System.out.println("getsubDetailFromGoogleApi :- Exception in method = " +e);
   }

打印出我的凭证,运行时是这样的: com.google.api.client.googleapis.auth.oauth2.GoogleCredential@42ed8060

当我收到错误时: bpr@46096240 由于在创建签名版本时出现问题。

希望有人以前见过这种行为!任何帮助将不胜感激!

angelwrq123 回答:错误 400 错误请求 - 无效的 grant_type,当调用 google play 开发者 API 以在 android 中获取订阅详细信息时

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/700184.html

大家都在问