console.log returns 没什么
console.log which returns nothing
我正在尝试设置一个登录屏幕,以便让用户通过 expo-facebook 通过 facebook 登录。
我想在 console.log 中检索用户的姓名和电子邮件以进行测试。
但是,终端中什么也没有。你能告诉我为什么吗?但是,我的帐户连接正常。谢谢你的助手。
logInViaFacebook = async () => {
try {
await Facebook.initializeAsync("34904");
const {
type,
token,
expires,
permissions,
declinedPermissions,
} = await Facebook.logInWithReadPermissionsAsync({
permissions: ["public_profile", "email"],
});
if (type === "success") {
// Get the user's name using Facebook's Graph API
const response = await fetch(
`https://graph.facebook.com/me?fields=id,name,email,birthday&access_token=${token}`
);
this.setState({
signedIn: true,
name: response.name,
email: response.email,
});
console.log(this.state.name, this.state.email,)
this.props.navigation.navigate("TabBar");
// saving the token in AsyncStorage
//await AsyncStorage.setItem('email', email); // <- save the email in AsyncStorage for later use
} else {
// type === 'cancel'
}
} catch ({ message }) {
alert(`Facebook Login Error: ${message}`);
}
}
setState
是异步的,因此您无法立即看到更新。要查看更新,您需要将回调作为 setState 的第二个参数传递。
this.setState({
signedIn: true,
name: response.name,
email: response.email,
}, () => {
console.log(this.state.name, this.state.email);
});
我正在尝试设置一个登录屏幕,以便让用户通过 expo-facebook 通过 facebook 登录。 我想在 console.log 中检索用户的姓名和电子邮件以进行测试。 但是,终端中什么也没有。你能告诉我为什么吗?但是,我的帐户连接正常。谢谢你的助手。
logInViaFacebook = async () => {
try {
await Facebook.initializeAsync("34904");
const {
type,
token,
expires,
permissions,
declinedPermissions,
} = await Facebook.logInWithReadPermissionsAsync({
permissions: ["public_profile", "email"],
});
if (type === "success") {
// Get the user's name using Facebook's Graph API
const response = await fetch(
`https://graph.facebook.com/me?fields=id,name,email,birthday&access_token=${token}`
);
this.setState({
signedIn: true,
name: response.name,
email: response.email,
});
console.log(this.state.name, this.state.email,)
this.props.navigation.navigate("TabBar");
// saving the token in AsyncStorage
//await AsyncStorage.setItem('email', email); // <- save the email in AsyncStorage for later use
} else {
// type === 'cancel'
}
} catch ({ message }) {
alert(`Facebook Login Error: ${message}`);
}
}
setState
是异步的,因此您无法立即看到更新。要查看更新,您需要将回调作为 setState 的第二个参数传递。
this.setState({
signedIn: true,
name: response.name,
email: response.email,
}, () => {
console.log(this.state.name, this.state.email);
});