
token = bundle.getString(AccountManager.KEY_AUTHTOKEN);
?
我在AndroID上获得新用户后,我需要将它们插入我的数据库服务器端,但我需要在此之前以某种方式验证该令牌.
我试图像这样使用令牌:
url = 'https://www.GoogleAPIs.com/oauth2/v1/userinfo?access_token=%s' % access_token
但谷歌正在返回“未经授权的访问”.
我该如何访问
https://www.GoogleAPIs.com/oauth2/v1/userinfo
使用AndroID AccountManager提供的’auth_token’?
解决方法 您可能只是在authTokenType前面缺少oauth2:前缀.此代码有效:
// Note the `oauth2:` prefixprivate static final String AUTH_TOKEN_TYPE_USERINFO_PROfile = "oauth2:https://www.GoogleAPIs.com/auth/userinfo.profile";// Todo: allow the use to choose which account to useAccount acct = accountManager.getAccountsByType("com.Google")[0];accountManager.getAuthToken(acct,AUTH_TOKEN_TYPE_USERINFO_PROfile,null,this,new AccountManagerCallback<Bundle>() { @OverrIDe public voID run(AccountManagerFuture<Bundle> future) { try { String accesstoken = future.getResult().getString( AccountManager.KEY_AUTHTOKEN); Log.i(TAG,"Got OAuth2 access token: " + accesstoken); /* Your code here. Use one of two options. In each case replace ... with the above OAuth2 access token: 1) GET https://www.GoogleAPIs.com/oauth2/v1/userinfo?access_token=... 2) GET https://www.GoogleAPIs.com/oauth2/v1/userinfo with this header: Authorization: Bearer ... */ } catch (OperationCanceledException e) { // Todo handle this case Log.w(TAG,"The user has dID not allow access"); } catch (Exception e) { // Todo handle this exception Log.w(TAG,"Unexpected exception",e); } } },null); }
总结以上是内存溢出为你收集整理的Android auth_token验证和使用服务器端全部内容,希望文章能够帮你解决Android auth_token验证和使用服务器端所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)