2015-04-03 237 views
0

我建立一個Android應用程序,其中用戶將登錄使用LinkedIn。如何在android中登錄linkedin?

當用戶點擊按鈕時,當我點擊接受時輸入電子郵件ID和密碼後出現默認linkedin登錄頁面我禁用以獲取用戶詳細信息。

下面是我的登錄代碼 -

public void onClick(View v) { 

    if (v.getId() == R.id.btnLinkedin) { 

     oAuthService = LinkedInOAuthServiceFactory.getInstance() 
       .createLinkedInOAuthService(Constants.CONSUMER_KEY, 
         Constants.CONSUMER_SECRET); 
     System.out.println("oAuthService : " + oAuthService); 

     factory = LinkedInApiClientFactory.newInstance(
       Constants.CONSUMER_KEY, Constants.CONSUMER_SECRET); 

     liToken = oAuthService 
       .getOAuthRequestToken(Constants.OAUTH_CALLBACK_URL); 

     Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(liToken 
       .getAuthorizationUrl())); 
     Toast.makeText(getApplicationContext(), "3", Toast.LENGTH_LONG).show(); 
     startActivity(i); 



    } 
} 

@Override 
protected void onNewIntent(Intent intent) { 
    super.onNewIntent(intent); 

    Toast.makeText(getApplicationContext(), "", Toast.LENGTH_LONG).show(); 

    try { 

     linkedInImport(intent); 
    } catch (NullPointerException e) { 
     e.printStackTrace(); 
    } 
} 

private void linkedInImport(Intent intent) { 
    String verifier = intent.getData().getQueryParameter("oauth_verifier"); 
    System.out.println("liToken " + liToken); 
    System.out.println("verifier " + verifier); 



    LinkedInAccessToken accessToken = oAuthService.getOAuthAccessToken(
      liToken, verifier); 
    client = factory.createLinkedInApiClient(accessToken); 

    // client.postNetworkUpdate("LinkedIn Android app test"); 

    Person profile = client.getProfileForCurrentUser(EnumSet.of(
      ProfileField.ID, ProfileField.FIRST_NAME, 
      ProfileField.LAST_NAME, ProfileField.HEADLINE)); 


    System.out.println("First Name :: " + profile.getFirstName()); 
    System.out.println("Last Name :: " + profile.getLastName()); 
    System.out.println("Head Line :: " + profile.getHeadline()); 

} 

回答