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?
我已經提到上述鏈接,但沒有得到電子郵件地址。 – Ravindhiran
https://github.com/magus/react-native-facebook-login/issues/176 試試看。我想你必須先登錄Facebook才能獲得電子郵件的詳細信息或類似的東西。 –