Javascript console.log,它不返回任何内容

Javascript console.log,它不返回任何内容,javascript,react-native,facebook-graph-api,Javascript,React Native,Facebook Graph Api,我正在尝试设置一个登录屏幕,以便让用户通过facebook世博会登录。 我想在console.log中检索用户的姓名和电子邮件,以进行测试。 然而,我在终点站什么也没有。你能告诉我为什么吗?但是,我的帐户的连接工作正常。谢谢你的帮助 logInViaFacebook = async () => { try { await Facebook.initializeAsync("34904"); const { type,

我正在尝试设置一个登录屏幕,以便让用户通过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}`);
  }
}
logInViaFacebook=async()=>{
试一试{
等待Facebook.initializeAsync(“34904”);
常数{
类型,
代币
到期,
权限,
取消许可,
}=等待Facebook.logInWithReadPermissionsAsync({
权限:[“公共_配置文件”、“电子邮件”],
});
如果(类型==“成功”){
//使用Facebook的Graph API获取用户名
const response=等待获取(
`https://graph.facebook.com/me?fields=id、姓名、电子邮件、生日和访问权\u令牌=${token}`
);
这是我的国家({
签名人:是的,
name:response.name,
电子邮件:response.email,
});
console.log(this.state.name、this.state.email)
this.props.navigation.navigate(“TabBar”);
//将令牌保存在异步存储中

//等待AsyncStorage。setItem('email',email);//
setState
是异步的,因此您无法立即看到更新。要查看更新,您需要将回调作为setState的第二个参数传递

this.setState({
   signedIn: true,
   name: response.name,
   email: response.email,
}, () => {
   console.log(this.state.name, this.state.email);
});
          

setState
是异步的,因此您无法立即看到更新。要查看更新,您需要将回调作为setState的第二个参数传递

this.setState({
   signedIn: true,
   name: response.name,
   email: response.email,
}, () => {
   console.log(this.state.name, this.state.email);
});
          

这是一个评论而不是答案(肯定有重复的)这是一个评论而不是答案(肯定有重复的)