1

I'm using SocialAuth library for integrating fb/linkedin. I've logged in successfully but i am to able to fetch user profile. My Code is given Below :

public class MainActivity extends Activity  implements View.OnClickListener{

Button fb,linkedIn;
SocialAuthAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    fb=(Button)findViewById(R.id.button);
    linkedIn=(Button)findViewById(R.id.button2);
    fb.setOnClickListener(this);
    linkedIn.setOnClickListener(this);

    adapter = new SocialAuthAdapter(new ResponseListener());
    adapter.addProvider(SocialAuthAdapter.Provider.FACEBOOK,R.drawable.facebook);
    adapter.addProvider(SocialAuthAdapter.Provider.LINKEDIN,R.drawable.linkedin);

    try{
        adapter.addConfig(SocialAuthAdapter.Provider.FACEBOOK,"901453509923310","29940b7c91f8a9d4db7e72f7e3e72e1d","publish_actions");

    }
    catch(Exception ex)
    {
        Log.e("Adding config",ex.toString());
    }


}


@Override
public void onClick(View view) {
    switch (view.getId()) {

        case R.id.button:
            adapter.authorize(MainActivity.this, SocialAuthAdapter.Provider.FACEBOOK);

            break;

        case R.id.button2:

            break;
    }


}

private final class ResponseListener implements DialogListener{

    @Override
    public void onComplete(Bundle bundle) {
        String token=adapter.getCurrentProvider().getAccessGrant().getKey();
        Log.e("KEY ",token);
        adapter.getUserProfileAsync(new ProfileDataListener());

    }

    @Override
    public void onError(SocialAuthError socialAuthError) {

        Log.e("ERRROR ", socialAuthError.getMessage());

    }

    @Override
    public void onCancel() {

    }

    @Override
    public void onBack() {

    }
}


private final class ProfileDataListener implements SocialAuthListener<Profile> {
    @Override
    public void onExecute(String s, Profile profile) {
        Profile profileMap = profile;

       // Log.d("Custom-UI","Validate ID         = " + profileMap.getValidatedId());
        Log.d("Info","First Name          = " + profileMap.getFirstName());
        Log.d("Info","Last Name           = " + profileMap.getLastName());
        Log.d("Info","Email               = " + profileMap.getEmail());
        Log.d("Info","Gender                   = " + profileMap.getGender());
        Log.d("Info","Country                  = " + profileMap.getCountry());
        Log.d("Info","Language                 = " + profileMap.getLanguage());
        Log.d("Info","Location                 = " + profileMap.getLocation());
        Log.d("Info","Profile Image URL  = " + profileMap.getProfileImageURL());

    }

    @Override
    public void onError(SocialAuthError socialAuthError) {
        Log.e("GETTING PROFILE INFO ",socialAuthError.getMessage());

    }
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}


}

After successfull Login I'm getting the following logcat :

enter image description here

Please Help i've stuck at this point. Thank you

Brucode
  • 205
  • 1
  • 3
  • 12
  • Possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – Selvin Nov 19 '15 at 14:31
  • Nope.. Its not a Duplicate issue with the link u shared @Selvin. I am having the similar kind of crash. I found out that It's because 'getUserProfileAsync' is unable to retrieve some data from Facebook graph API and because of that a JsonParseException occurs which results to some params remains NULL. Trying to figure out why.. – Ankur Dec 23 '15 at 13:01
  • lol, yes it is ... profile is null because it was never assiged (and link explains how to check what is null) ... why? it is a different problem (but that's how end bad/no exception/error handling) ... his code land in onError(doesn't matter why ... it could be internet shortage) but he want use this unassigned variable – Selvin Dec 23 '15 at 13:07

2 Answers2

1

you can use facebook sdk instead of social auth

ManishNegi
  • 569
  • 1
  • 6
  • 19
0

It seems that you don't ask for user profile permissions. in facebook SDK it looks like this

mFacebookLoginManager.logInWithReadPermissions(this, Arrays.asList("public_profile", "email"));

So I guess somewhere in SocialAuth there is a line to ask for permissions. Also, you have to sign your app with app ID, which facebook gives you after you register as a facebook developer.

RexSplode
  • 1,475
  • 1
  • 16
  • 24