gpt4 book ai didi

android - 检查您的 google-services 插件配置,未填充 default_web_client_id 字符串

转载 作者:行者123 更新时间:2023-12-04 01:45:14 26 4
gpt4 key购买 nike

我刚开始使用 Firebase,并设计了一个简单的程序来测试 FirebaseUI 登录。我收到一个异常,即未填充默认 Web 客户端 ID 字符串。

Github https://github.com/firebase/FirebaseUI-Android/issues/1381 上有一个关于此的问题但它似乎被我抛弃了。我已将 gradle 依赖项更新到最新版本,但仍然没有运气。

这是代码:

(MainActivity.java)

package uk.ac.le.cityTourPlanner;

import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.firebase.ui.auth.AuthUI;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;

import java.util.Arrays;
import java.util.List;

public class MainActivity extends AppCompatActivity {

private FirebaseAuth mFirebaseAuth;
private FirebaseAuth.AuthStateListener mAuthStateListener;
private static int RC_SIGN_IN = 1 ;

List<AuthUI.IdpConfig> providers = Arrays.asList(
new AuthUI.IdpConfig.EmailBuilder().build(),
new AuthUI.IdpConfig.GoogleBuilder().build()
);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mFirebaseAuth=FirebaseAuth.getInstance();
mAuthStateListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if(user!=null){
Toast.makeText(MainActivity.this, "user signed in!", Toast.LENGTH_LONG).show();
}
else{
startActivityForResult(AuthUI.getInstance().createSignInIntentBuilder().setAvailableProviders(providers).
setIsSmartLockEnabled(false).build(),RC_SIGN_IN);
}
}
};
}

@Override
protected void onResume() {
super.onResume();
mFirebaseAuth.addAuthStateListener(mAuthStateListener);
}

@Override
protected void onPause() {
super.onPause();
mFirebaseAuth.removeAuthStateListener(mAuthStateListener);
}

public void signOut(View view) {
AuthUI.getInstance().signOut(this).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Toast.makeText(MainActivity.this, "user signed out!", Toast.LENGTH_LONG).show();
finish();
}
});
}
}

(MainActivity.xml)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:layout_centerInParent="true"
android:textSize="25dp"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text"
android:id="@+id/button"
android:text="Sign Out"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:textSize="25dp"
android:onClick="signOut"/>

</RelativeLayout>

(AndroidManifest.xml)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="uk.ac.le.cityTourPlanner">

<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">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

</manifest>

最后

(谷歌服务.json)
{
"project_info": {
"project_number": "921658610309",
"firebase_url": "https://city-tour-planner.firebaseio.com",
"project_id": "city-tour-planner",
"storage_bucket": "city-tour-planner.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:921658610309:android:0a33483e26b227f2",
"android_client_info": {
"package_name": "uk.ac.le.cityTourPlanner"
}
},
"oauth_client": [
{
"client_id": "921658610309-10djmoc7i9k3doou7sq8sg4aog8v78jf.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "uk.ac.le.cityTourPlanner",
"certificate_hash": "fff5b002b82089efa22081bac552cc6b8ccab44c"
}
}
],
"api_key": [
{
"current_key": "AIzaSyD6OWj9Roi1bm40jiD54B3V-h5FsgqaJ-0"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "921658610309-4dhq16mrdgfd45jkrt0vo9hmlr1m4ju7.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}

最佳答案

引用这个类似的question (同样的错误,我 answered 也适用于我的情况)。

基本上,只需添加 default_web_client_id进入您的 string.xml 文件,如下所示:

<string name="default_web_client_id" translatable="false">webClientId.apps.googleusercontent.com</string>

或将其添加到 google-services.json文件的 Oauth 部分是这样的(通常你不应该这样做,但对于这种情况,我在 answer 中解释了原因:
"oauth_client": [
...,
{
"client_id": "CLIENT_ID (ends with apps.googleusercontent.com)",
"client_type": 3
}
]

您可以找到 default_web_client_id在您的 GCP console喜欢 this

go to API & Services > Credentials and under OAuth 2.0 client IDs you will find a ID with the name Web Client

关于android - 检查您的 google-services 插件配置,未填充 default_web_client_id 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55532079/

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