我想使用linkedIn api在我的Android应用程序中使用SocialAuth实现登录链接功能

时间:2013-11-07 11:31:02

标签: android api linkedin socialauth

我在使用linkedIn登录后编写了以下代码片段以获取用户详细信息。但点击按钮后,没有任何反应。如何将我重定向到linkedin登录页面?请帮忙

公共类MainActivity扩展了Activity {

SocialAuthAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final SocialAuthAdapter adapter = new SocialAuthAdapter(new ResponseListener());


    Button linkedin_button = (Button)findViewById(R.id.button1);

    //adapter.enable(linkedin_button);
    linkedin_button.setOnClickListener(new OnClickListener() 
    {
       public void onClick(View v) 
       {
           adapter.authorize(MainActivity.this, Provider.LINKEDIN);
       }
   });

  }

private final class ResponseListener implements DialogListener 
{
   public void onComplete(Bundle values) {

     //SocialAuthAdapter adapter = null;
    adapter.getUserProfileAsync(new ProfileDataListener());                   
   }
}

//在身份验证后接收配置文件响应     私有final类ProfileDataListener实现SocialAuthListener {

public void onExecute(Profile t) {

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

}    

}

http://www.3pillarglobal.com/blog/part-2-using-socialauth-integrate-linkedin-api-android

1 个答案:

答案 0 :(得分:1)

将此添加到您的活动

// To receive the response after authentication
        private final class ResponseListener implements DialogListener {
        @Override
        public void onComplete(Bundle values) {

            Log.d("Custom-UI", "Successful");

            // Get the provider
            providerName = values.getString(SocialAuthAdapter.PROVIDER);
            Log.d("Custom-UI", "providername = " + providerName);

            Toast.makeText(MainActivity.this, providerName + " connected", Toast.LENGTH_SHORT).show();

            mDialog = new ProgressDialog(MainActivity.this);
            mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            mDialog.setMessage("Loading.......");

            adapter.getUserProfileAsync(new ProfileDataListener());

            Toast.makeText(MainActivity.this, "Display Details", Toast.LENGTH_LONG).show();
        }

        @Override
        public void onError(SocialAuthError error) {
            Log.d("Custom-UI", "Error");
            error.printStackTrace();
        }

        @Override
        public void onCancel() {
            Log.d("Custom-UI", "Cancelled");
        }

        @Override
        public void onBack() {
            Log.d("Custom-UI", "Dialog Closed by pressing Back Key");

        }
    }