【发布时间】:2014-02-22 02:14:19
【问题描述】:
当我尝试连接到 Google 坐标时,我总是收到异常 GoogleAuthException。
我有 Google 地图协调中心许可证。 我确实使用我的包应用程序名称和我的 SHA1 在谷歌控制台中创建了我的客户端 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"/>
我使用这个代码:
final String SCOPE = "oauth2:https://www.googleapis.com/auth/coordinate";
try {
mGoogleCoordinatetoken = GoogleAuthUtil.getToken(activity, email, SCOPE);
Log.e(getClass().getSimpleName(), "token ="+mGoogleCoordinatetoken);
} catch (GooglePlayServicesAvailabilityException playEx) {
Log.e(getClass().getSimpleName(), "GooglePlayServicesAvailabilityException "+playEx.getMessage());
} catch (UserRecoverableAuthException userAuthEx) {
// Start the user recoverable action using the intent returned by
// getIntent()
Log.e(getClass().getSimpleName(), "UserRecoverableAuthException "+userAuthEx.getMessage());
} 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(getClass().getSimpleName(), "IOException "+transientEx.getMessage());
} catch (GoogleAuthException authEx) {
// Failure. The call is not expected to ever succeed so it should not be
// retried.
Log.e(getClass().getSimpleName(), "GoogleAuthException "+authEx.getMessage());
}
知道如何解决这个异常吗?
例外:
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
【问题讨论】:
-
如果您只需要令牌来进一步验证您的服务器后端,那么您可以使用“String SCOPE = “audience:server:client_id:”+Constants.WED_CLIENT_ID;”作为你的范围
-
如果你要使用范围“oauth2:googleapis.com/auth/coordinate”那么你必须走与 Madhur Ahuja 建议的相同的路线..Bacuase 这个范围只是不给你令牌..它首先需要用户授权..只有这个范围“audience:server:client_id:”直接给你称为跨客户端身份的令牌
-
我想获取工作列表,例如:developers.google.com/coordinate/v1/jobs/list,我不需要令牌吗?
-
可以粘贴异常吗?
-
它清楚地表明这需要授权..你需要在你的其他范围内尝试“googleapis.com/auth/coordinate”..试试这个stackoverflow.com/questions/17827256/…
标签: android google-maps oauth-2.0