2017-06-15 76 views
1

我試圖訪問用戶的電子郵件和名稱來設置和帳戶時,用戶驗證與Facebook。我已經準備好了react-native-fbsdk的文檔,但是我只能獲取accesstoken,userID,name,但是獲得了電子郵件地址。react-native-fbsdk:如何獲取用戶信息,如電子郵件,名字,姓氏?

facebookLoginTapped() 
{ 
LoginManager.logInWithReadPermissions(['email']).then(
function(result) { 
if (result.isCancelled) { 
    alert('Login was cancelled'); 
} else { 
    alert('Login success with permissions: ' + JSON.stringify(result)); 

    AccessToken.getCurrentAccessToken().then((data) => { 
     const { accessToken } = data 

    fetch(`https://graph.facebook.com/me?access_token=${data.accessToken.toString()}`) 
       .then((response) => response.json()) 
       .then((res) => { 
       var socialOptions = { 
        email: res.email, 
        firstName: res.first_name, 
        lastName: res.last_name, 
        token: data.accessToken.toString(), 
        uid: data.userID, 
        loginType: 'facebook', 
       } 
       alert(JSON.stringify(socialOptions 
       )) 
       // ignore this--custom api call sending the data to my own api 
       api.socialRegister(socialOptions) 
        .then((response) => { 
        // working 
        this.handleResponse(response); 

        }) 
        .catch((error) => console.log('error', error)) 
       }) 
       .catch((err) => console.log('error occurred', err.message)); 
       }) 
} 
}, 
function(error) { 
alert('Login failed with error: ' + error); 
} 
); 
} 

我提到下面的鏈接,但沒有得到電子郵件地址:How to get user info (email, name, etc.) from the react-native-fbsdk?

回答

0

如何獲得從反應本地-fbsdk用戶信息(電子郵件,姓名等)?

check out試試這個解決方案。這幾乎正​​是你想要的

+0

我已經提到上述鏈接,但沒有得到電子郵件地址。 – Ravindhiran

+0

https://github.com/magus/react-native-facebook-login/issues/176 試試看。我想你必須先登錄Facebook才能獲得電子郵件的詳細信息或類似的東西。 –

相關問題