sejwalsakshi
Lurker
I am trying to read subscription details by using google play developer API but am seeing an interesting behavior. When running my app through Android Studio (as Debug variant) I am able to download objects. When I create a Signed APK (or run as Release variant) I am no longer able to download subscription detail by using google play developer API and receive a 400 bad request - invalid grant_type.
This is my authorization method:
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);
}
Printing out my credential, it looks like this when running: com.google.api.client.googleapis.auth.oauth2.GoogleCredential@42ed8060
and this when I receive an error: bpr@46096240 Since the issue occurs when creating a signed release.
Hopefully someone has seen this type of behavior before! Any help would be greatly appreciated!!
This is my authorization method:
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);
}
Printing out my credential, it looks like this when running: com.google.api.client.googleapis.auth.oauth2.GoogleCredential@42ed8060
and this when I receive an error: bpr@46096240 Since the issue occurs when creating a signed release.
Hopefully someone has seen this type of behavior before! Any help would be greatly appreciated!!