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

98
Views
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 answers
Answer question

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 Report
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!