无法使用SocialAuth

时间:2015-11-19 14:17:08

标签: android facebook socialauth

我正在使用 SocialAuth 库来整合fb / linkedin。我已成功登录但我能够获取用户个人资料。我的代码如下:

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);
}


}

成功登录后,我收到以下logcat:

enter image description here

请帮助我坚持到这一点。谢谢

2 个答案:

答案 0 :(得分:1)

你可以使用facebook sdk代替社交认证

答案 1 :(得分:0)

您似乎没有要求用户个人资料权限。在facebook SDK中,它看起来像这样

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

所以我想在SocialAuth的某个地方有一行要求权限。此外,您必须使用应用程序ID为您的应用程序签名,Facebook在您注册成为Facebook开发人员后会给您。