I am trying Google Sign In using React-native-google-signin plugin but it gives me DEVELOPER_ERROR
error. I have done exactly same as mention in its documentation. Here are my code and steps.
Installed react-native-google-signin
plugin using npm i react-native-google-signin
command.
Then I've linked it with react-native link react-native-google-signin
After that I did setup of build.gradle
file as they mention it in the documentation.
ext {
buildToolsVersion = "27.0.3"
minSdkVersion = 16
compileSdkVersion = 27
targetSdkVersion = 26
supportLibVersion = "27.1.1"
googlePlayServicesAuthVersion = "15.0.1"
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.google.gms:google-services:3.2.1'
}
allprojects {
repositories {
mavenLocal()
google()
maven {url "https://maven.google.com"}
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
}
Updated the android/app/build.gradle
dependencies {
implementation 'com.facebook.android:facebook-android-sdk:4.34.0'
implementation project(':react-native-fbsdk')
compile project(':react-native-vector-icons')
compile project(':react-native-fused-location')
compile project(':react-native-fs')
compile project(':react-native-image-resizer')
compile project(':react-native-geocoder')
compile project(':react-native-device-info')
compile project(':react-native-image-picker')
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
compile "com.facebook.react:react-native:+" // From node_modules
implementation project(":react-native-google-signin")
compile (project(':react-native-maps')){
exclude group: "com.google.android.gms"
}
implementation 'com.google.android.gms:play-services-auth:15.0.1'
implementation 'com.google.android.gms:play-services-maps:15.0.1'
implementation 'com.google.android.gms:play-services-location:15.0.1'
implementation 'com.google.android.gms:play-services-base:15.0.1'
}
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
apply plugin: 'com.google.gms.google-services'
Then generated the SHA1 key using Android Studio debug.keystore
and generated the google-services.json
file in the Firebase console.
Then I set up the login.js
page like this:
async componentDidMount() {
this._configureGoogleSignIn();
}
_configureGoogleSignIn() {
GoogleSignin.configure({
webClientId: '775060548127-5nfj43q15l75va9pfav2jettkha7hm2a.apps.googleusercontent.com',// my clientID
offlineAccess: false
});
}
async GoogleSignin() {
try {
await GoogleSignin.hasPlayServices();
const userInfo = await GoogleSignin.signIn();
// this.setState({ userInfo, error: null });
Alert.alert("success:" + JSON.stringify(userInfo));
} catch (error) {
if (error.code === statusCodes.SIGN_IN_CANCELLED) {
// sign in was cancelled
Alert.alert('cancelled');
} else if (error.code === statusCodes.IN_PROGRESS) {
// operation in progress already
Alert.alert('in progress');
} else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
Alert.alert('play services not available or outdated');
} else {
Alert.alert('Something went wrong', error.toString());
this.setState({
error,
});
}
}
}
These are my details so please someone help me on this. I cannot find the appropriate solution online and yes my SHA1 key and clientID
is correct. I've checked it already.
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.