I am trying to use Google APIs Client Library for Java to get information about user’s subscriptions purchased in my android app. Then I got this error:
{ "code" : 401, "errors" : [ { "domain" : "androidpublisher", "message" : "The current user has insufficient permissions to perform the requested operation.", "reason" : "permissionDenied" } ], "message" : "The current user has insufficient permissions to perform the requested operation." }
I am trying those steps:
- Go to https://console.cloud.google.com
- Create a project (or select existing project)
- Create a service account with role Pub/Sub Admin
- Go to https://console.cloud.google.com/apis/library and search for “Google Play Android Developer API”
- Enable that API
- Go to https://play.google.com/apps/publish
- Go to Settings > Developer account > API Access
- Link the project that you created in step 2
- The service account will appear that you created in step 3
- Grant access to it with Finance permission to the app in play console
- Wait for at least 24 hours for changes to take effect.
I am trying this code :
httpTransport = new com.google.api.client.http.javanet.NetHttpTransport(); JacksonFactory jsonFactory = JacksonFactory.getDefaultInstance(); String applicationName = "App name"; String packageName = "com.example.xxx"; final Set<String> scopes = Collections.singleton(AndroidPublisherScopes.ANDROIDPUBLISHER); AssetManager am = getAssets(); InputStream inputStream = am.open("key1.p12"); File file = createFileFromInputStream(inputStream); Log.d(TAG, "file : " + file); if(file != 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("pp-subscription@practice-presto-dev.iam.gserviceaccount.com").setServiceAccountScopes(scopes) //.setServiceAccountId("practice-presto-subscription@practice-presto-dev.iam.gserviceaccount.com").setServiceAccountScopes(scopes) .setServiceAccountPrivateKeyFromP12File(file).build(); AndroidPublisher pub = new AndroidPublisher.Builder (httpTransport, jsonFactory, credential) .setApplicationName(applicationName) .build(); final AndroidPublisher.Purchases.Subscriptions.Get get = pub.purchases().subscriptions().get(packageName, "sub_monthly_pro", "pcehicpbjhcdnjockiniaokh.AO-J1OxsJtLehF3z_naoXR4LE0jqiXrABAPYiZMNRMZO5jnKI9gnyHmPP7INtcc2kyptNKP_HM6MjEPQfmYWmJ8R_geonsLqMXA9TLsozqNexh-FxSvQFDZSUTgBW_azvdAJPLxPFuKd"); final SubscriptionPurchase purchase = get.execute(); Log.d(TAG, "Found google purchase item " + purchase.toPrettyString()); } }
I am using testing In-App Purchase mode.
I want to fetch the latest subscription receipt after renewing subscription plan.
Advertisement
Answer
I have checked after 24 hours there was an error. But after that, I have checked again after two days there was no error and the data has been received.