java - How to use Purchase Status API -


i'm developing app has several non-consumable inapp products in , need purchase status of directly sending requests google server , receiving result. understood "purchase status api" gives possibility it's not working me. made needed settings in "google api console": switched on "google play android developer api". created client id app. tried use methods described on here: http://developer.android.com/google/play-services/auth.html methods googleauthutil.gettoken(); , googleauthutil.gettokenwithnotification(); throwing me "unknown exception". managed access token using 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, have no idea token. if try authenticate 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 "file not found exception". if try purchase status of 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 json looks this:

{ "error": { "errors": [ { "domain": "global", "reason": "required", "message": "login required", "locationtype": "header", "location": "authorization" } ], "code": 401, "message": "login required" } } 

i'm desperately looking solution several days. i'll glad if provide me solution or date documentation on point.

so looking on code , information try couple things, first verifying access token. have used this reference. using browser , simple html page (see below) able acquire token , verify it. need need fill out values specified on page.

make sure token correct first. did using userinfo address in browser.

next inapp purchase html location needs ?access_token={access_token} @ end after if notice section "accessing api" in above page authorization, need add this.

here webpage have used token testing. note testing , not work final solution because authorization token short time. need make sure code gets access token functions correctly. in addition again refer page above fill out product. thing dynamic in "code" value comes instructions on page.

hope of can you...

<form action=" https://accounts.google.com/o/oauth2/token" method="post"> <input name="grant_type" type="hidden" value="authorization_code" /> <input name="code" type="hidden" value="the code previous step"/> <input name="client_id" type="hidden" value="the client id token created in apis console"/> <input name="client_secret" type="hidden" value="the client secret corresponding client id"/> <input name="redirect_uri" type="hidden" value="the uri registered client id"/> <input type="submit" />
</form>


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -