通过这个代码。
googleAuthenticate = (token) => {
const provider = firebase.auth.GoogleAuthProvider();
const credential = provider.credential(token)
return firebase.auth().signInWithCredential(credential) }
gglogin = async () => {
const LogInResult = await Google.logInAsync({
androidClientId: '<my-androidClientId>',
iosClientId: '<my-IOSClientId>',
scopes: ['profile', 'email']
});
if(LogInResult.type === 'success'){
Alert.alert(
'Logged in!',
`Hi ${user.name}!`,
);
this.googleAuthenticate(LogInResult.accessToken)
}}
它可以获得用户名警报,但不能通过获得此错误向firebase发送令牌。
Possible Unhandled Promise Rejection (id: 0):
TypeError: this.addScope is not a function. (In
'this.addScope("profile")', 'this.addScope' is undefined)`请问哪里不对劲?
发布于 2017-06-19 14:26:42
我注意到两个问题,credential是一个静态方法,第一个参数是一个id令牌,第二个参数是一个访问令牌(看起来你在传递一个访问令牌):
const credential = firebase.auth.GoogleAuthProvider.credential(null, token);
return firebase.auth().signInWithCredential(credential);发布于 2017-06-18 00:22:06
您必须将您的作用域添加到provider,如下所示:
var provider = new firebase.auth.GoogleAuthProvider();
provider.addScope('profile');
provider.addScope('email');
firebase.auth().signInWithRedirect(provider);请重新检查此文档:https://firebase.google.com/docs/reference/js/firebase.auth.GoogleAuthProvider
您需要更改代码,如下所示:
googleAuthenticate = (token) => {
const provider = firebase.auth.GoogleAuthProvider();
provider.addScope('profile');
provider.addScope('email');
const credential = provider.credential(token)
return firebase.auth().signInWithCredential(credential) }https://stackoverflow.com/questions/44606687
复制相似问题