Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

178
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda