Search code examples
javascriptandroidfacebookauthenticationaccount-kit

Access Account Information on the Device using JavaScript sdk


I am using JavaScript sdk of Account-Kit but unable to get the phone-number in the response packet Please find relevant link for this:- https://developers.facebook.com/docs/accountkit/webjs/reference

function loginCallback(response) {
console.log(response.status);
console.log(response.code);
console.log(response.state);

/* Not able to get user account information 
  if (response.status === "PARTIALLY_AUTHENTICATED") {
    // Send code to server to exchange for access token
  }
  else if (response.status === "NOT_AUTHENTICATED") {
    // handle authentication failure

  }
  else if (response.status === "BAD_PARAMS") {
    // handle bad parameters
  }
}

There is a function written for Android to Access Account Information on the Device but I didn't find for the web in javascript.


Solution

  • The AccountKit JS SDK returns an authorization code after successful login that you need to exchange for an access token. After you have this access token you can hit the '/me' endpoint to get the phone number.

    See: https://developers.facebook.com/docs/accountkit/accesstokens https://developers.facebook.com/docs/accountkit/webjs#examplenodejs