react-native-fbsdk 라이브러리 github을 보며 적용하던중 로그인 시 유저게 email정보를 요청하고 해당 정보를 받아오려고 하는데 공식문서에서는 해당 내용을 찾기가 힘들었다.
이 과정이 필요했던 이유는 소셜로그인(facebook)을 했을때, 회원가입하는 계정의 userID로 사용할 정보를 얻어내야했다.
async facebookLogin() {
const result:any = await LoginManager.logInWithPermissions(["public_profile", "email"])
if (result.isCancelled) {
console.log("Login cancelled");
} else {
const data = await AccessToken.getCurrentAccessToken()
if (data) {
new GraphRequestManager().addRequest(new GraphRequest(
'/me',{
parameters: {
'fields': {
'string' : 'email, name'
}
}
}, (err, obj:any)=> {
if (obj) {
console.log(obj)
const {AuthAct, auth, navigation} = this.props
AuthAct.socialSign('facebook', data.userID, obj.name, obj.email, data.accessToken, auth.fcmToken)
.then(res=> navigation.navigate('Home'))
}
}
)).start()
}
}
}
permission 정보로 email을 추가 요청한다.
const result:any = await LoginManager.logInWithPermissions(["public_profile", "email"])
GraphRequest의 두번째 인자로 parameter를 작성하여 넘겨 준다.
GraphRequest( '/me',{ parameters: { 'fields': { 'string' : 'email, name' } } }, (err, obj:any)=> { if (obj) { console.log(obj) const {AuthAct, auth, navigation} = this.props AuthAct.socialSign('facebook', data.userID, obj.name, obj.email, data.accessToken, auth.fcmToken) .then(res=> navigation.navigate('Home')) } } )