錯誤:'idpiframe_initialization_failed',詳細資訊:'您創建了一個新的客戶端應用程式,使用...即將被棄用的身份驗證或授權。新客戶端必須改用新庫;現有客戶端也必須在這些庫被棄用之前遷移。有關更多資訊,請參閱
uj5u.com熱心網友回復:
Gapi 登錄方式將于 2023 年 3 月棄用,不會使用。所以你必須使用這里提到的新方式
更新:您也可以將 plugin_name 添加到您的代碼中以繞過如下錯誤:
window.gapi.client
.init({
clientId:'Your Client ID',
scope: "email",
plugin_name:'App Name that you used in google developer console API'
})
uj5u.com熱心網友回復:
檢查這些博客 https://github.com/anthonyjgrove/react-google-login/issues/502
或試試這些
這是我正在使用的。
首先,我有一個名為 useScript 的通用鉤子,它可以將任何標簽加載到 HTML 頭中,并且在腳本完全加載時有一個回呼函式:
import { useEffect } from "react";
const useScript = (url, onl oad) => {
useEffect(() => {
const script = document.createElement("script");
script.src = url;
script.onload = onl oad;
document.head.appendChild(script);
return () => {
document.head.removeChild(script);
};
}, [url, onl oad]);
};
export default useScript;
然后我創建了一個加載 Google 按鈕的 GoogleLogin 組件。
import { useRef } from "react";
import useScript from "hooks/useScript";
export default function GoogleLogin({
onGoogleSignIn = () => {},
text = "signin_with",
// feel free to add more options here
}) {
const googleSignInButton = useRef(null);
useScript("https://accounts.google.com/gsi/client", () => {
window.google.accounts.id.initialize({
client_id: process.env.REACT_APP_GOOGLE_CLIENT_ID,
callback: onGoogleSignIn,
});
window.google.accounts.id.renderButton(
googleSignInButton.current,
{ theme: "outline", size: "large", text, width: "250" } // customization attributes
);
});
return <div className="test" ref={googleSignInButton}></div>;
}
很簡單!
uj5u.com熱心網友回復:
您可以使用@react-oauth/google它使用新的 google 服務標識 SDK
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/475683.html
標籤:反应 验证 谷歌身份验证 google-api-js-客户端 谷歌作者
上一篇:JSON回應TypeError-'“資料”引數必須是字串型別'
下一篇:XUnit測驗起訂量失敗
