Android 谷歌坐标认证
当我尝试连接到Google coordinate时,总是会出现异常Android 谷歌坐标认证,android,google-maps,oauth-2.0,Android,Google Maps,Oauth 2.0,当我尝试连接到Google coordinate时,总是会出现异常GoogleAuthException 我有谷歌地图坐标许可证。 我确实用我的包应用程序名和我的SHA1在google控制台中创建了我的客户端Id 我已将权限添加到清单文件: <uses-permission android:name="android.permission.GET_ACCOUNTS"/> <uses-permission android:name="android.permission.NETW
GoogleAuthException
我有谷歌地图坐标许可证。
我确实用我的包应用程序名和我的SHA1在google控制台中创建了我的客户端Id
我已将权限添加到清单文件:
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.NETWORK"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
<uses-permission android:name="android.permission.INTERNET"/>
你知道我如何修复这个异常吗
例外情况:
01-30 22:24:53.968: E/getAccessToken()(24800): [ERROR] GoogleAuthException: com.google.android.gms.auth.GoogleAuthException: Unknown
01-30 22:24:53.998: E/AccessTokenTask(24800): mGoogleCoordinatetoken =null
问题是你为什么需要得到代币。正如您在我的问题中所评论的,您应该可以使用GoogleAccountCredential对象。一旦您拥有凭证对象,就可以调用Google API
credential = GoogleAccountCredential.usingOAuth2(this, scopes);
if (TextUtils.isEmpty(appPreferences.getUserName()))
{
try
{
startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER);
}
catch (ActivityNotFoundException e)
{
Toast.makeText(this, getString(R.string.gps_missing), Toast.LENGTH_LONG).show();
return;
}
}
我遇到了完全相同的问题,通过将范围修改为:
"oauth2:https://www.googleapis.com/auth/[API YOU WANT]"
(乞讨很重要!)
希望它能帮助某人:)如果您只需要令牌在服务器后端进行进一步验证,那么您可以使用“String SCOPE=”观众:服务器:客户端\u id:“+常量.WED\u客户端\u id;”作为您的作用域,如果您要使用作用域“oauth2:”然后,您必须按照Madhur Ahuja建议的路线行事..因为此作用域不给您令牌..它首先需要用户授权..只有此作用域“受众:服务器:客户端\u id:”直接给您令牌,称为跨客户端标识我想要获取作业列表,例如:,我不需要令牌来执行此操作?您可以粘贴异常吗?它清楚地表明这需要授权..您需要在其他作用域中尝试“”尝试此操作我想获取作业列表例如:我不需要令牌来执行此操作?我收到错误登录请求我使用的是客户端id而不是WEB应用程序客户端id。
String WEB_APPLICATION_CLIENT_ID = "656631023202-9jsg9faqe87n1uo7f5g6iupti1jl2nps.apps.googleusercontent.com";
String scopes = String.format("audience:server:client_id:" + WEB_APPLICATION_CLIENT_ID );
Log.e(getClass().getSimpleName(), "email ="+email);
String code = null;
try {
code = GoogleAuthUtil.getToken(
LoginActivity.this, // Context context
email, // String accountName
scopes
);
mGoogleCoordinatetoken = code;
} catch (IOException transientEx) {
// network or server error, the call is expected to succeed if you try again later.
// Don't attempt to call again immediately - the request is likely to
// fail, you'll hit quotas or back-off.
Log.e("getAccessToken()", "[ERROR] IOException: " + transientEx);
} catch (UserRecoverableAuthException e) {
// Recover
Log.e("getAccessToken()", "[ERROR] UserRecoverableAuthException: " + e);
code = null;
} catch (GoogleAuthException authEx) {
// Failure. The call is not expected to ever succeed so it should not be
// retried.
Log.e("getAccessToken()", "[ERROR] GoogleAuthException: " + authEx);
} catch (Exception e) {
Log.e("getAccessToken()", "[ERROR] Exception: " + e);
throw new RuntimeException(e);
}
"oauth2:https://www.googleapis.com/auth/[API YOU WANT]"