当一个用户通过Facebook认证时,我试图访问该用户的邮箱和姓名以设置和帐户.我已经准备好了react native fbsdk的文档,但我哪儿都没看到.

推荐答案

你可以这样做(这是我在我的应用程序中所做的简化版本):

<LoginButton
  publishPermissions={['publish_actions']}
  readPermissions={['public_profile']}
  onLoginFinished={
    (error, result) => {
      if (error) {
        console.log('login has error: ', result.error)
      } else if (result.isCancelled) {
        console.log('login is cancelled.')
      } else {
        AccessToken.getCurrentAccessToken().then((data) => {
          const { accessToken } = data
          initUser(accessToken)
        })
      }
    }
  }
  onLogoutFinished={logout} />

//功能initUser

initUser(token) {
  fetch('https://graph.facebook.com/v2.5/me?fields=email,name,friends&access_token=' + token)
  .then((response) => response.json())
  .then((json) => {
    // Some user object has been set up somewhere, build that user here
    user.name = json.name
    user.id = json.id
    user.user_friends = json.friends
    user.email = json.email
    user.username = json.name
    user.loading = false
    user.loggedIn = true
    user.avatar = setAvatar(json.id)      
  })
  .catch(() => {
    reject('ERROR GETTING DATA FROM FACEBOOK')
  })
}

React-native相关问答推荐

领带麦克风在Reaction-Native-Incall-Manager中不工作

expo 使用错误的版本代码创建建筑

React Native 动画.您必须在转换属性中精确指定一个属性.

哪个版本的@stripe/stripe-react-native 模块支持 react native 0.62.0 typscript 模板?

react-native react-native-vector-icons:如何使用字体真棒图标

React Native Expo - 不再支持 Node.js 版本 11.13.0

react-native app.js index.js

如何在 react-native 中获取组件的大小?

使用 create-react-native-app 创建了一个应用程序,如何将其发布到 Google Play store ?

通过带有对象子对象的数组react native 映射 - 与react网络中的工作方式不同?

我可以在 react-native 中使用 reactJS 库吗?

将 svg 转换为 react-native-svg

如何在 Expo 和 React Native 中使用绝对路径导入?

使用来自另一个页面的 fetch 调用函数返回结果值

react-native如何禁用android开发模式

React Native Bullet Character? or Unicode?

React Native - __DEV__ 未定义

react-native-webview :对于 iOS 文本太小

从标题中的按钮导航到不同的屏幕

React Native font outline / textShadow