gpt4 book ai didi

android - 谷歌坐标认证

转载 作者:太空宇宙 更新时间:2023-11-03 11:57:56 25 4
gpt4 key购买 nike

当我尝试连接到 Google 坐标时,我总是遇到异常 GoogleAuthException

我拥有 Google map 协调中心许可。我确实在谷歌控制台中使用我的包应用程序名称和我的 SHA1 创建了我的客户端 ID。

我将权限添加到我的 list 文件中:

<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());
}

知道如何解决这个异常吗?

异常(exception):

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 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);
}

关于android - 谷歌坐标认证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21445265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com