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

99
Vistas
Facebook Graph request with async await

I want to make a call to my backend (registerSanctumFacebook method) after a facebook Graph request to get user profile info (email), however I'm getting the following error:

await is only allowed within async functions

Pretty self explanatory, the problem is, I don't know how to make graph start method to work with async-await...

const getInfoFromToken = async (token) => {
        const PROFILE_REQUEST_PARAMS = {
          fields: {
            string: 'email',
          },
        };
        const profileRequest = new GraphRequest(
          '/me',
          {token, parameters: PROFILE_REQUEST_PARAMS},
          (error, user) => {
            if (error) {
              console.log('login info has error: ' + error);
            } else {
              //this.setState({userInfo: user});
              console.log('user:', user);
              
            }
          },
        );
        new GraphRequestManager().addRequest(profileRequest).start();
        let response = await registerSanctumFacebook(user.email,user.id);
        
    };

How I call getTokenInfo method:

const loginWithFacebook = async () => {
        LoginManager.logInWithPermissions(['email']).then(
          login => {
            if (login.isCancelled) {
              console.log('Login cancelled');
            } else {
              AccessToken.getCurrentAccessToken().then(data => {
                const accessToken = data.accessToken.toString();
                console.log('accessToken',accessToken);
                getInfoFromToken(accessToken);
              });
            }
          },
          error => {
            console.log('Login fail with error: ' + error);
          },
        );
    };
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

As per your problem statement, I think you should add await on this line

    await new GraphRequestManager().addRequest(profileRequest).start();

await will only work if the function after await keyword is also async.

or declare registerSanctumFacebook as async

about 4 years ago · Juan Pablo Isaza Denunciar
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