首页 > 解决方案 > React Native 连接与 firebase 错误:“请提供适当的客户端 ID”

问题描述

错误:请提供适当的客户 ID

首先我创建了一个 firebase 项目,然后我创建了两个应用程序(Android 和 iOS)。在创建 Android 之后,我安装了 .json 文件,然后在构建 apk 之后,通过命令“expo fetch:android:hashes”,我刚刚获得了谷歌证书哈希(SHA-256),我在谷歌中输入了指纹应用程序。使用 IOS,我在创建应用程序后下载了 .plist 文件。

代码:

const config = {
  androidClientId:
    "//ID from client_id of the google json file",
  iosClientId:
     "//ID from string of the google plist file",
  scopes: ["profile", "email"],
  permissions: ["public_profile", "email", "gender", "location"],
};

export const AuthProvider = ({ children }) => {
  const signInWithGoogle = async () => {
    await Google.logInAsync(config).then(async (loginResults) => {
      if (loginResults.type === "success") {
        //success
      }
    });
  };

  return (
    <AuthContext.Provider
      value={{
        user: null,
        signInWithGoogle,
      }}
    >
      {children}
    </AuthContext.Provider>
  );
};

export default function useAuth() {
  return useContext(AuthContext);
}

APP.js

const { signInWithGoogle } = useAuth();

  return (
    <View>
      <Button title="Login" onPress={signInWithGoogle} />
    </View>
  );

仅打印出客户端 ID 错误后,没有打开谷歌模式

标签: javascriptandroidfirebasereact-nativefirebase-authentication

解决方案


推荐阅读