skip to Main Content

I am using Facebook Login for Android. It works. I can log in through the emulator. However, I need to send back information to my Rails Rest API. Upon facebook callback success, I want to send back the access token, the provider (“facebook”), the uid, facebook user name, facebook user email and the facebook image icon.

loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
  @Override
  public void onSuccess(LoginResult loginResult) {
    Log.i("AUTHENTICATION TOKEN", String.valueOf(loginResult.getAccessToken()));
  }  

Logcat shows the following:

I/AUTHENTICATION TOKEN: {AccessToken token:ACCESS_TOKEN_REMOVED permissions:[public_profile, contact_email, email]}

How do I get the information I need onSuccess?

2

Answers


  1. try this

    Log.i("AUTHENTICATION TOKEN", AccessToken.getCurrentAccessToken().getToken());
    
    Login or Signup to reply.
  2. Once you have the access token obtained using LoginResult.getAccessToken(),

    You need to call the Facebook Graph api using the access token received. From the SDK Docs,

    GraphRequest request = GraphRequest.newMeRequest(
            accessToken,
            new GraphRequest.GraphJSONObjectCallback() {
                @Override
                public void onCompleted(
                       JSONObject object,
                       GraphResponse response) {
                    // Application code
                }
            });
    Bundle parameters = new Bundle();
    parameters.putString("fields", "id,name,email");
    request.setParameters(parameters);
    request.executeAsync()
    

    The JSONObject object will contain the required user information provided the user has granted all the necessary permissions to your application

    The list of fields available for user can be seen here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search