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:
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("[email protected]").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.
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.