尽管已授予所有权限,react-native fbsdk仍返回未定义的电子邮件

时间:2019-01-30 15:01:32

标签: react-native react-native-fbsdk

我正试图通过facebook sdk获取信息,但到目前为止,我只获得了ID和用户名。我确实已经授予了权限,但是仍然弹出电子邮件,例如名称和ID。我几乎尝试了一切。

任何帮助将不胜感激。

预先感谢

      import React, { Component } from 'react'
       import { View, TouchableOpacity, Text } from 'react-native';
         import { LoginButton, AccessToken, LoginManager, GraphRequest, 
           GraphRequestManager } from 'react-native-fbsdk';

              export default class App extends Component {
               constructor() {
              super();
                this._fbAuth = this._fbAuth.bind(this);
                          }
                      _fbAuth = () => {
               var that = this;
             LoginManager.logInWithReadPermissions(['public_profile', 
             'email']).then(function (result) {
                if (result.isCancelled) {
           console.log("Login Cancel");
           alert("Login Cancel")
              //debugger
            }
             else {
               console.log("Login AccessToken");
               alert("Login AccessToken");
              AccessToken.getCurrentAccessToken().then(
                       (data) => {
        //      alert("Get AccessToken");
        //debugger
              let accessToken = data.accessToken;
             alert(accessToken.toString());
               const responseInfoCallback = (error, result) => {
            setTimeout(() => {
            if (error) {
              alert('Errorrrrrrrrr');

            }
            else {
              if (result.email == undefined) {
                alert("Error ,Email address is required");
                // stuck at email. result.name and result.id gives correct results

              }
              else {
                alert(result.email);
              }
            }
          }, 200
          );
        }
        const infoRequest = new GraphRequest(
          '/me',
          {
            accessToken: accessToken,
            prameters: {
              fields: {
                string: 'email , name,first_name, middle_name, last_name'
              }
            }
          },
          responseInfoCallback
        );
        new GraphRequestManager().addRequest(infoRequest).start();

               })
                  }
                  },
           function (error) {
            console.log("some error occured!!", error);
          })

            }

           render() {
         return (
             <View>
             <TouchableOpacity onPress={() => this._fbAuth()}>
               <Text>  Press me</Text>
           </TouchableOpacity>
            </View>
        );
             }

                   }

result.email不应未定义。

1 个答案:

答案 0 :(得分:0)

您可以只使用accessToken提供的fbsdk。 只需获取accessToken,当您收到accessToken后,就可以使用accessToken向facebook graph api请求接收与该用户相关的数据。

https://developers.facebook.com/docs/graph-api/using-graph-api

此处是完整文档,并且还包含accessToken。它会帮助你。 我也一样。