Getting and using a google glass oauth2 access token from an android app -


i trying glass access token post glass timeline within android application. user able select information , send glass device.

string token = googleauthutil.gettoken(activity, memail, activity.getstring(r.string.glass_token_scope)); 

where memail google glass user's google account email, , scope is:

oauth2:https://www.googleapis.com/auth/glass.timeline https://www.googleapis.com/auth/glass.location https://www.googleapis.com/auth/userinfo.profile 

(oauth2: ...)

i using google authutil , return access token, too. when use access token, api responds 401 unauthorized:

d/demo    (10804): response code: 401 d/demo    (10804): { d/demo    (10804):  "error": { d/demo    (10804):   "errors": [ d/demo    (10804):    { d/demo    (10804):     "domain": "global", d/demo    (10804):     "reason": "autherror", d/demo    (10804):     "message": "invalid credentials", d/demo    (10804):     "locationtype": "header", d/demo    (10804):     "location": "authorization" d/demo    (10804):    } d/demo    (10804):   ], d/demo    (10804):   "code": 401, d/demo    (10804):   "message": "invalid credentials" d/demo    (10804):  } d/demo    (10804): } 

i've setup server-side oauth2 flow , resulting access token can create timeline post a little local script.

it seems access token returned android authutil cannot used glass mirror api. checked google apis console , see can create android specific client ids. created client id androdi application , setup simple api access android. sha1 fingerprint used debug certificate's sha1.

has succeeded on getting glass token on android , has been making request android phone token?

for actual request using plain httpurlconnection - issue?

        httpurlconnection con = (httpurlconnection)new url(uri_timeline).openconnection();         con.setrequestmethod("post");         con.setdooutput(true);         con.setrequestproperty("authorization", "bearer " + token);         con.setrequestproperty("content-type", "application/json");         con.getoutputstream().write(content.tostring().getbytes("utf-8")); 

thx!

in order valid oauth 2.0 token on android, need use google play services apis, googleauthutil class.

you need register certificate on apis console; suggest checking out drive sdk quickstart android describes steps.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -