我试图从android应用程序中获取玻璃访问令牌以发布到玻璃时间轴。用户能够选择一些信息并将其发送到他的玻璃装置。从Android应用程序获取并使用谷歌眼镜oauth2访问令牌
String token = GoogleAuthUtil.getToken(activity, mEmail, activity.getString(R.string.glass_token_scope));
其中mEmail是谷歌玻璃用户的谷歌帐户的电子邮件,并且范围是:
oauth2:https://www.googleapis.com/auth/glass.timeline https://www.googleapis.com/auth/glass.location https://www.googleapis.com/auth/userinfo.profile
(的oauth2:...)
我使用的是谷歌AuthUtil和它的回报一个访问令牌。但是当我使用的访问令牌,该API与401未授权回应:
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): }
我已经成功地也设置服务器端OAuth2流程,并用所得访问令牌,我可以成功地创建从AA小时间表后本地脚本。
真的好像从Android Authutil返回的访问令牌不能与Glass Mirror API一起使用。我查看了Google API控制台,看到您可以创建一些Android特定的客户端ID。所以我为一个androdi应用程序创建了一个客户端ID,并为Android设置了简单的API访问。对于SHA1指纹,我使用了调试证书的SHA1。
有没有人成功获得Android上的Glass令牌,并且已经成功通过该令牌从android手机发出请求?
对于实际的请求,我使用普通的HttpURLConnection - 这可能是问题吗?
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!
嗨,Alain,我使用GoogleAuthUtil类 - 你可以在我贴的代码中看到它。我还获得了一个访问令牌,迄今为止所有的作品。但是当我使用这个使用正确的玻璃示波器创建的访问令牌时,我得到了一个401 Not Authorized来自服务器。 –
我现在已经切换到服务器端 - 例如我将一个标识符传递给一个私人代理服务器,代理服务器(应用程序引擎)对谷歌镜像API执行调用。它的工作原理... –
我也创建了一个oauth2 cleint id并使用设置窗体“已安装的应用程序” - 我还添加了软件包名称和sha1指纹。我想问题是我接着执行“手动”REST API调用。在这些调用中,我无处设置SHA1指纹。我假设Google API自动执行此操作。有没有办法做到这一点手动?我想自己使用REST api,我不想使用提供的API来执行许多事情,而无需我的控制。 –