Created
February 8, 2023 07:53
-
-
Save PaperMonster/6f75f9455fca7a4216fa5e3bb944132f to your computer and use it in GitHub Desktop.
Get gender and birthday from Facebook Graph API in React Native
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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