簡體   English   中英

反應原生谷歌登錄返回狀態代碼:12501

[英]react native google signin return status code: 12501

我需要讓谷歌登錄我的本機應用程序。 所以我用谷歌搜索了很多,我發現react-native-google-signin看起來很棒,但我遇到了一個錯誤。

我遵循READ.meAndroide 指南中的所有步驟

我有以下代碼:

 componentDidMount() {


     GoogleSignin.hasPlayServices({autoResolve: true}).then(() => {
        // play services are available. can now configure library
        GoogleSignin.configure({
            scopes: [
                'email', 'profile', 'https://www.googleapis.com/auth/plus.profile.emails.read', 'https://www.googleapis.com/auth/plus.login'
            ],
            webClientId: 'web-clientid from the console developper',
            offlineAccess: true
        }).then(() => {
            // you can now call currentUserAsync()
            GoogleSignin.currentUserAsync().then((user) => {
                console.log('USER', user);
            }).done();
        });
     });
}

signIn() {
    GoogleSignin.signIn()
        .then((user) => {
            console.log(user);
        })
        .catch((err) => {
            console.log('WRONG SIGNIN', err);
        })
        .done();
}

 render() {
    return (
        <Image source={BACKGROUND} style={styles.container}>
            <Image source={ICON}></Image>
            <Text style={styles.welcome}>
                APP TEST
            </Text>

            <GoogleSigninButton
                style={{width: 230, height: 48}}
                size={GoogleSigninButton.Size.Standard}
                color={GoogleSigninButton.Color.Light}
                onPress={this.signIn}
            />
        </Image>
    );

當我單擊登錄按鈕時,會彈出一個窗口,供我選擇要使用的 Google 帳戶。 但是當我選擇帳戶時,出現以下錯誤:WRONG SIGNIN 錯誤:未知狀態代碼:12501(...)

因此,我查看了Androide 指南底部的常見問題解答,並確認我在android/app/google-services.json中的 certificate_hash 是相同的。 我還檢查了我的app/build.graddle中的app/build.graddle是否與我在谷歌雲中輸入的相同。

我認為問題出在我在范圍內傳遞的 WebclientId,我傳遞的是 web 類型 1,但已經嘗試了 oauth 2 中的兩個客戶端 ID

屏幕

我在 githubs 問題中搜索,我發現有人告訴我再次下載 google-services。 我這樣做了,但該文件與我之前下載的文件相同。 很確定,我錯過了一些東西,但沒有什么。 有人可以幫助我嗎?

我在 github 中打開了一個問題,但我沒有得到太多的行動。

提前致謝

您共享的自述文件指出

D. 登錄完成后,我收到以下錯誤錯誤代碼 12501。該怎么辦?

這是權限錯誤。 確保 android/app/google-services.json 中的 certificate_hash 與您的證書匹配。

獲取你的 sha1-hash

keytool -exportcert -keystore ~/.android/debug.keystore -list -v 還要確保應用程序 ID 與您在雲控制台上輸入的 ID 匹配。

有一個 .user 文件(或類似的文件),我一時想不起來了。 它位於隱藏文件夾中,因此您必須使用查找器查找該文件並將其刪除。 它應該工作。 查看您的代碼用來查找它的所有路徑,您將不得不調試這些文件的路徑。

這可能會幫助你,試試這個:

  • 檢查您的 google-services.json cirtificate_hash 代碼。 將其與您的 Android 簽名證書 SHA-1 匹配。 使用此鏈接訪問他們的https://developers.google.com/mobile
  • 我已經在模擬器上測試過了,但模擬器沒有谷歌播放服務,所以我在我的安卓手機上測試了它。
  • 使用空閑代碼

    import {GoogleSignin, GoogleSigninButton} from 'react-native-google-signin';

那么

componentDidMount() {
    GoogleSignin.configure({
        scopes: [
            'email', 'profile', 'https://www.googleapis.com/auth/plus.profile.emails.read', 'https://www.googleapis.com/auth/plus.login'
        ],
        webClientId: 'use here oauth_client[{client_id}]',//refer this given below example:
        offlineAccess: true
    }).then(() => {
        // you can now call currentUserAsync()
        GoogleSignin.currentUserAsync().then((user) => {
             //user = GoogleSignin.currentUser();
            console.log('USER', user);
            this.setState({user: user});
        }).done();
    });
}

_signIn() {
    GoogleSignin.signIn()
        .then((user) => {
            console.log('this1' + JSON.stringify(user));                
        })
        .catch((err) => {
            console.log('WRONG SIGNIN', err);
        })
        .done();
}

_signOut(){
    GoogleSignin.signOut()
        .then(() => {
            console.log('out');
        })
        .catch((err) => {

        });
}

render() {

    return (
        <View style={styles.container}>
            <Text style={styles.welcome}>
                Welcome to React Native!
            </Text>
            <Text style={styles.instructions}>
                To get started, edit index.android.js
            </Text>
            <Text style={styles.instructions}>
                Double tap R on your keyboard to reload,{'\n'}
                Shake or press menu button for dev menu
            </Text>
            <GoogleSigninButton
                style={{width: 48, height: 48}}
                size={GoogleSigninButton.Size.Icon}
                color={GoogleSigninButton.Color.Dark}
                onPress={this._signIn.bind(this)}/>
            <TouchableHighlight>
                <Text onPress={this._signOut.bind(this)}>
                    signout
                </Text>
            </TouchableHighlight>
        </View>
    );
}

:example --> webClientId: '1059..........googleusercontent.com' 他們是 google-services.json oauth_client[] 中的兩個客戶端 ID,使用第一個。 您可以將其與https://console.developers.google.com/apis/credentials下方給出的憑據鏈接進行比較...名稱:Web 客戶端類型:Web 應用程序客戶端 ID:1059........googleusercontent。電腦

這解決了我的問題。 有一個美好的一天。 謝謝。:)

即使我正在傳真這個問題,我也按照以下步驟解決了它。

  1. 創建密鑰庫並使用 SHA-1 證書指紋。
  2. https://console.developers.google.com/apis/credentials創建 OAuth 客戶端 ID 在此處輸入圖片說明
  3. 選擇Application type android,輸入包名,輸入步驟1中創建的SHA-1證書指紋。

對調試和生產 SHA-1 證書指紋重復上述步驟。

注意:我們需要按照上述步驟為APP SIGNATURE后生成的SHA-1再創建一個OAuth客戶端ID 在此處輸入圖片說明

注意:我們還沒有完成,再創建一個 web-application OAith Client id 並在你的 react app 中使用 web application client id 在此處輸入圖片說明 希望這對像我這樣的人有所幫助!!!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM