使用React Native实施Google+登录 [英] Implement Google+ Sign-In with React Native
问题描述
我想集成Google+登录(根据 https://React Native应用中的developers.google.com/+/mobile/ios/signin ).我通过 http://brentvatne.ca/facebook-login-with进行Facebook登录-react-native/可以正常工作,但是我不确定在G +文档的这一点该做什么:
I'm wanting to integrate G+ Sign In (as per https://developers.google.com/+/mobile/ios/sign-in) in a React Native app. I have Facebook Sign In working via http://brentvatne.ca/facebook-login-with-react-native/ which is working perfectly, but I'm not sure what to do at this point of the G+ docs:
在视图控制器的.h文件中,导入GooglePlus/GooglePlus.h,并声明该控制器类实现了GPPSignInDelegate协议
In your view controller's .h file, import GooglePlus/GooglePlus.h, and declare that this controller class implements the GPPSignInDelegate protocol
是否有人可以提供一些指针/代码示例?
If anyone could provide some pointers/code samples?
谢谢!
推荐答案
编辑2017
在Expo框架(现在是本机应用程序的默认框架)中,内置了Google身份验证:
Within the Expo framework, which is now the default for react-native apps, there is built in Google Authentication available:
Expo文档: https://docs.expo.io/versions/Latest/sdk/google.html
获取Android和iOS客户端ID: https://console.developers.google.com/api/凭证
Get Android and iOS client ids: https://console.developers.google.com/apis/credentials
import React from 'react'
import Expo from 'expo'
import Button from 'react-native-button'
class Login extends React.Component {
signInWithGoogleAsync = async () => {
try {
const result = await Expo.Google.logInAsync({
androidClientId: process.env.GOOGLE_ANDROID_CLIENT_ID,
iosClientId: process.env.GOOGLE_IOS_CLIENT_ID,
scopes: ['profile'],
})
if (result.type === 'success') {
return result
}
return { cancelled: true }
} catch (e) {
return { error: e }
}
}
onLoginPress = async () => {
const result = await this.signInWithGoogleAsync()
// if there is no result.error or result.cancelled, the user is logged in
// do something with the result
}
render() {
return (<Button onPress={this.onLoginPress}>Login</Button>)
}
}
旧答案
现在有一个用于使用Google+登录本机以响应本机的库: https: //github.com/devfd/react-native-google-signin
There is now a library for signing in with Google+ for react-native: https://github.com/devfd/react-native-google-signin
这篇关于使用React Native实施Google+登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!