2016-07-23 118 views
2

我需要谷歌登錄我的反應本機應用程序。所以我谷歌了很多,我發現react-native-google-signin看起來很棒,但我堅持一個錯誤。反應原生谷歌登錄返回狀態代碼:12501

我遵循READ.meAndroide Guide

所有步驟我有以下代碼:

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> 
    ); 

當我登入]按鈕點擊,彈出一個窗口,我選擇哪一個谷歌帳戶我想用。但是當我選擇的賬戶中,我有如下錯誤:錯誤登錄錯誤:未知狀態代碼:12501(...)

所以我期待在中Androide Guide 底部野兔的常見問題,並確認我在android/app/google-services.json certificate_hash是相同的。 我還檢查我的app/build.graddle中的應用ID是否與我在Google雲中輸入的相同。

我覺得現在的問題是與我通過我的範圍WebclientId,我是經過的網絡類型之一,但已經嘗試了兩個客戶端ID是在OAuth 2

screen

我在githubs問題搜索,我發現有人告訴再次下載谷歌服務。我這樣做,但該文件等於我以前下載的文件。 很確定,我失去了一些東西,但不是什麼。 任何人都可以幫助我嗎?

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

在此先感謝

回答

1

,我不記得了我的頭頂部的自述您共享狀態

D. After the sign-in completes I get the following error error code 12501. what to do ?

This is a permission error. Make sure the certificate_hash in android/app/google-services.json matches your certificate.

To get your sha1-hash

keytool -exportcert -keystore ~/.android/debug.keystore -list -v Also make sure the application id matches the one you enter on the cloud console.

有一個。用戶文件(或類似的東西)。它位於隱藏文件夾中,因此您將不得不使用查找器來查找該文件並將其刪除。它應該工作。看看你的代碼用來找到它的所有路徑,你將不得不爲路徑調試這些文件。

+0

感謝您的幫助。但是我不明白你說的是什麼。如何找到隱藏文件,當我不知道名稱? – Jacinto

+0

您將不得不調試文件路徑的代碼並將其檢出。 –

+1

他的意思是FAQ - https://github.com/devfd/react-native-google-signin/blob/master/android-guide.md#d-after-the-sign-in-completes-i-get-在跟隨誤差,錯誤碼12501-什麼到做 - – r0ma

0

也許這會幫助你,試試這個:

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

    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> 
    ); 
} 

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

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