Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

188
Views
How to get 'public_Profile' of the user from the Facebook access_token using OAuth2

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;

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!