2016-07-23 114 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

这解决了我的问题。 祝您有美好的一天。 谢谢。:)