gpt4 book ai didi

android - Google 登录失败 (ApiException : 8 )

转载 作者:行者123 更新时间:2023-12-04 12:35:58 25 4
gpt4 key购买 nike

当我尝试通过 google 登录时,出现此异常

2020-11-12 13:32:51.571 7351-7351/com.test.app W/aaab: com.google.android.gms.common.api.ApiException: 8


这是什么意思?
代码
public class MainActivity extends AppCompatActivity {

private GoogleSignInClient mGoogleSignInClient;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mGoogleSignInClient = GoogleSignIn.getClient(this, new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN).build());
Button btnSignIn = (Button) findViewById(R.id.btn_sign_in);
btnSignIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivityForResult(mGoogleSignInClient.getSignInIntent(), 100);
}
});
}

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 100) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
if (task.isSuccessful()) {
Toast.makeText(this, "Done", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Failed", Toast.LENGTH_SHORT).show();
Log.w("aaab","" + task.getException());
}
try {
GoogleSignInAccount account = task.getResult(ApiException.class);
} catch (ApiException ignored) {

}
}
}}
这是 list ...................................................... ………………
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.test.app">

<uses-permission android:name="android.permission.INTERNET"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="892959183721" />
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

最佳答案

尝试这个

GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN).requestEmail().build();
还要确保将您的应用程序 ID 外包给资源文件。
<!-- This works -->
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="@string/app_id" />

<!-- This is returning an error -->
<meta-data android:name="com.google.android.gms.games.APP_ID"
android:value="12345678" />

关于android - Google 登录失败 (ApiException : 8 ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64803668/

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