I wanted to use facebook login in the app. I successfully get Facebook Accesstoken and even the user info {id:'###', name:'###'}. But I wanted the users Email and other public_Profile info to register his email and other details. How can I do that. Following is my code..Did my scope values are wrong? how can I get public_profile info, particularly email to register it in my app.
const getFbToken = async (code) => {
const tokenUrl = "https://graph.facebook.com/v12.0/oauth/access_token";
const queryValues = {
code,
client_id: FB_APP_ID,
client_secret: FB_SECRET,
redirect_uri: redirect_uri, // address must match with google redirect uri
scope:"user_about_me,read_stream,publish_actions,user_birthday,offline_access,email",
};
const token = await axios
.get(tokenUrl, {
headers: {
"Content-Type": "application/json",
},
params:queryValues
})
.then((res) => {
console.log('response', res.data)
return res.data
}
) // returns {{access_token, refresh_token, Authorization Bearer and id_token}}
.catch((error) => {
console.error(`Failed to fetch auth tokens`, error.response.data);
});
console.log(token);
return token;
};
const getFbUser = async (access_token, token_type) => {
const fbUser = await axios
.get(
`https://graph.facebook.com/me`,
{
headers: {
Authorization: `Bearer ${access_token}`,
"Content-Type": "application/json",
},
}
)
.then((res) => res.data)
.catch((error) => {
console.error(`Failed to fetch user`);
throw new Error(error.message);
});
console.log('fbUser',fbUser)
return fbUser;