React-native google signin gives Developer Error

后端 未结 8 1862
日久生厌
日久生厌 2021-02-02 17:53

I am trying Google login using React-native-google-signin plugin but it gives me a Developer_Error.I have done exctly same as mention in its document.here is my code ans steps.<

相关标签:
8条回答
  • 2021-02-02 18:26

    I think sometime it may possible for an old fingerprint (from a different dev in a former time) could be conflicting. So SHA1 should be proper. Delete the old SHA-1 and re-download google-services.json

    0 讨论(0)
  • 2021-02-02 18:27

    It's just because of your androidClientId is a mismatch as your google console project

    1. create your new auth client id from your project API console : https://console.developers.google.com/apis/credentials

    2. update configuration to: myfile.js like:

    GoogleSignin.configure({ androidClientId:'YOUR CLIENT ID' )}

    0 讨论(0)
  • 2021-02-02 18:35

    In my case, my SHA-1 key that I add to firebase project is invalid because I get it from /Users/apple/.android/debug.keystore.

    The correct SHA-1 should be got from the android folder inside the Project example: /Users/apple/Documents/Project/testGoogleFirebaseLogin/android/app/debug.keystore (testGoogleFirebaseLogin is my project folder name)

    So, the most convenient way is cd android && ./gradlew signingReport it will generate many many lines of data, scrolling to find and use the SHA-1 from the one that has Store: (your project path)

    NOTE: not the one that has Store: /Users/apple/.android/debug.keystore.

    (Apologize to my English skill, I will be appreciated if some one correct my gramma and make this answer is easier to read)

    0 讨论(0)
  • 2021-02-02 18:36

    I had this problem too and trawled through many answers saying check your client Id and key hash, both of which I was positive were right.

    The thing that got it working for me was I opened OAuth identities in the project management console (not Firebase) at https://console.cloud.google.com/apis/credentials and added an Android Oauth client Id with the correct signature (I did not have one of these there prior for some reason). Redownload the GoogleServices json file.

    I also needed to set the webClientId to the "client_type": 3 Oauth client ID. It then worked.

    0 讨论(0)
  • 2021-02-02 18:38

    I was trying keytool -exportcert -keystore ~/.android/debug.keystore -list -v which of course was giving me a SHA1 key but it was not working, after searching for a while I also look closer into my project/android/app folder and found that there is a debug.keystore key too (whose default password is android, in case some need to know ) so I tried cd android and keytool -exportcert -keystore app/debug.keystore -list -v command and the key I got, worked really well. I hope it will help.

    0 讨论(0)
  • 2021-02-02 18:39

    For React native projects:

    There are many items in the checklist to get rid of DEVELOPER_ERROR. There seems to be lot of confusion around where the SHA-1 key needs to be set.

    Once you have created android client_id in Google developer console you have an option to set SHA-1 key and package name.

    You can get the package name from AndroidManifest.xml (projPath/android/app/src/main/AndroidManifest.xml) and set it in the text box in google developer console(very important to check for typos).

    Then fetch your SHA-1 key from debug.keystore using following command for which password is "android"

    First figure out location of keystore:

    Your app may be either picking from

         `pathToReactNativeProj/projName/android/app/debug.keystore`
    

    or: ~/.android/debug.keystore

    Then fetch your SHA-1 key from debug.keystore using following command for which password is android

    keytool -exportcert -alias androiddebugkey -keystore pathToKeyStore -list -v

    copy paste the SHA-1 key generated . This should solve the issue.

    Code looks like following:

    try {
          GoogleSignin.configure(
          {
            //webClientId is required if you need offline access
            offlineAccess: true,
            webClientId:'2423432-43234234232432423234.apps.googleusercontent.com',
            androidClientId: '3242343242322432-2342323432232324343323.apps.googleusercontent.com',
            scopes: ['profile', 'email']
          });
          await GoogleSignin.hasPlayServices();
          console.log("reached google sign in");
          const userInfo = await GoogleSignin.signIn();
          console.log(userInfo);
          this.setState({ userInfo });
        } catch (error) {
          if (error.code === statusCodes.SIGN_IN_CANCELLED) {
            console.log("error occured SIGN_IN_CANCELLED");
            // user cancelled the login flow
          } else if (error.code === statusCodes.IN_PROGRESS) {
            console.log("error occured IN_PROGRESS");
            // operation (f.e. sign in) is in progress already
          } else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
            console.log("error occured PLAY_SERVICES_NOT_AVAILABLE");
          } else {
            console.log(error)
            console.log("error occured unknow error");
          }
        }
    

    Confusion around firebase SHA-1 key:

    Setting this key is not required for fetching user info from google. Unless you are using firebase to store your users data you fetched from google you need not worry about it.

    0 讨论(0)
提交回复
热议问题