Reputation: 2636
I am trying to get a glass access token to post to the glass timeline from within an android application. the user is able to select some information and send that to his glass device.
String token = GoogleAuthUtil.getToken(activity, mEmail, activity.getString(R.string.glass_token_scope));
where mEmail is the google glass user's Google Account email, and 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 am using the Google AuthUtil and it does return an access token, too. But when I use the access token, the API responds with 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 successfully also setup the server-side Oauth2 flow and with the resulting access token I can successfully create a timeline post from a a little local script.
It really seems that the access token returned from the Android Authutil cannot be used with the Glass Mirror API. I checked back to the Google APIs console and see that you can create some Android specific client ids. So I created a client ID for an androdi application and also setup the simple API access for android. For the SHA1 fingerprint I used the debug certificate's SHA1.
Has anyone succeeded on getting a Glass token on Android and has been successfully making a request from the android phone with that token?
For the actual request I using a plain HttpURLConnection - could that be the 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!
Upvotes: 3
Views: 840
Reputation: 6034
In order to get a valid OAuth 2.0 token on Android, you will need to use the Google Play Services APIs, especially the GoogleAuthUtil class.
You will also need to register your certificate on the APIs Console; I would suggest checking out the Drive SDK Quickstart for Android that describes those steps.
Upvotes: 1