I'm developing an app which has several non-consumable inApp products in it and i need to get the purchase status of those by directly sending requests to Google server and receiving the result. As i understood "Purchase Status API" gives that possibility but it's not working for me. I made all the needed settings in "Google API Console": Switched on "Google Play Android Developer API". Created a client ID for my App. I tried to use the methods described over here: http://developer.android.com/google/play-services/auth.html But the methods GoogleAuthUtil.getToken(); and GoogleAuthUtil.getTokenWithNotification(); are throwing me an "Unknown exception". However i managed to get the access token by using this code:
AccountManager acountM=AccountManager.get(Utils.curentActivity);
Account[] acount=acountM.getAccountsByType("com.google");
String AUTH_TOKEN_TYPE = "oauth2:https://www.googleapis.com/auth/androidpublisher";
AccountManagerFuture<Bundle> future=acountM.getAuthToken(acount[0], AUTH_TOKEN_TYPE, null, Utils.curentActivity, null, null);
try{
String token=future.getResult().getString(AccountManager.KEY_AUTHTOKEN);
}catch(Exception e){e.printStackTrace();}
But after this, i have no idea what to do with this token. If i try to Authenticate like this:
URL url=new URL("https://www.googleapis.com/oauth2/v1/userinfo?access_token="+token);
URLConnection conection=url.openConnection();
conection.setDoInput(true);
conection.connect();
InputStream is=conection.getInputStream();
It throws me a "File not found exception". If i try to get the purchase status of a product:
String packageName=MainActivity.this.getPackageName();
String productId="SKU_KEY_1";
HttpClient client=new DefaultHttpClient();
HttpGet get=new HttpGet("https://www.googleapis.com/androidpublisher/v1.1/applications/"+packageName+"/inapp/"+productId+"/purchases/"+token);
HttpResponse response=client.execute(get);
InputStream is=response.getEntity().getContent();
String result=Utils.readInputStream(is);
is.close();
The result is a JSON which looks like this:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
I'm desperately looking for a solution for several days. I'll will be glad if somebody will provide me a solution or an up to date documentation on this point.