当我按google登录按钮控制台日志时,它显示错误4:已取消 我不知道是什么问题,有人可以告诉我这个问题吗? 下面的app.js代码将显示 一对一的控制台错误 在该控制台日志中显示了已取消的错误4。
我的MainApplication.java
import co.apptailor.googlesignin.RNGoogleSigninPackage;
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RNGoogleSigninPackage()
);
}
code:
Code i used in android /app/build.gradle
android/app/build.gradle
dependencies {
implementation(project(":react-native-google-signin")){
exclude group: "com.google.android.gms"
}
implementation 'com.google.android.gms:play-services-auth:15.0.0'
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+"
}
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
我在android /build.gradle中使用的代码
android / build.gradle buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.google.gms:google-services:3.2.1'
}
}
allprojects {
repositories {
mavenLocal()
maven {url "https://maven.google.com"}
jcenter()
google()
maven {
url "$rootDir/../node_modules/react-native/android"
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '4.4'
distributionUrl = distributionUrl.replace("bin", "all")
}
APP.js
import { GoogleSignin, GoogleSigninButton,statusCodes } from 'react-native-google-signin';
export default class App extends Component {
componentWillMount(){
GoogleSignin.configure({
scopes: ['https://www.googleapis.com/auth/drive.readonly'],
webClientId: '***',
});
}
signIn = async () => {
try {
await GoogleSignin.hasPlayServices();
const userInfo = await GoogleSignin.signIn();
this.setState({ userInfo });
console.log(userInfo);
} catch (error) {
if (error.code === statusCodes.SIGN_IN_CANCELLED) {
console.log('1'+error);
// user cancelled the login flow
} else if (error.code === statusCodes.IN_PROGRESS) {
console.log('2'+error);
// operation (f.e. sign in) is in progress already
} else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
console.log('3'+error);
// play services not available or outdated
} else {
console.log('4'+error);
// some other error happened
}
}
};