Skip to content

Instantly share code, notes, and snippets.

@PaperMonster
Created February 8, 2023 07:53
Show Gist options
  • Save PaperMonster/6f75f9455fca7a4216fa5e3bb944132f to your computer and use it in GitHub Desktop.
Save PaperMonster/6f75f9455fca7a4216fa5e3bb944132f to your computer and use it in GitHub Desktop.
Get gender and birthday from Facebook Graph API in React Native
import {
LoginManager as FBLoginManager,
GraphRequest, GraphRequestManager
} from 'react-native-fbsdk-next';
function getGenderAndBirthdayFromFacebookLogin() {
FBLoginManager.logInWithPermissions(['public_profile', 'user_gender', 'user_birthday'])
.then((result) => {
if (result.error) {
showAlert('ไม่สามารถล็อกอิน Facebook ได้', result.error.message)
} else if (!result.isCancelled) {
const infoRequest = new GraphRequest(
'/me?fields=gender,birthday',
null,
function (error, graphResult) {
if (error) {
showAlert('ไม่สามารถขอข้อมูลจาก Graph API ได้', error.toString())
} else {
showAlert('เพศและอายุ', JSON.stringify(graphResult));
}
}
);
// Start the graph request.
new GraphRequestManager().addRequest(infoRequest).start();
}
})
.catch((error) => {
showAlert('ไม่สามารถล็อกอิน Facebook ได้', error.message)
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment