Not getting Email Address from linkedin?
Asked Answered
S

1

5

I m trying to get email address from linkedin user after authenticate now i m getting basic profile but not getting email address.

I m using http://code.google.com/p/linkedin-j/downloads/list jar file for authentication.

i have read this document care fully but not use full for me http://oodlestechnologies.com/blogs/recent-changes-in-linkedin-api.

Below code for jar file properties :-

# API URLs
##########
# Profile API
com.google.code.linkedinapi.client.getProfileForCurrentUser=http://api.linkedin.com/v1/people/~{profileFields}
com.google.code.linkedinapi.client.getProfileById=http://api.linkedin.com/v1/people/id={id}{profileType}{profileFields}
com.google.code.linkedinapi.client.getProfileByUrl=http://api.linkedin.com/v1/people/url={url}{profileType}{profileFields}

#OAuth URLs
###########
com.google.code.linkedinapi.client.oauth.requestToken=https://api.linkedin.com/uas/oauth/requestToken
com.google.code.linkedinapi.client.oauth.accessToken=https://api.linkedin.com/uas/oauth/accessToken
com.google.code.linkedinapi.client.oauth.authorize=https://www.linkedin.com/uas/oauth/authorize
com.google.code.linkedinapi.client.oauth.invalidateToken=https://api.linkedin.com/uas/oauth/invalidateToken

when i m change on anything on above and creating jar its show error.

now i m shown my code :-

void startAutheniticate() {

        System.out.println("OAUTH_CALLBACK_URL   " + OAUTH_CALLBACK_URL);

        final LinkedInRequestToken liToken = oAuthService
                .getOAuthRequestToken(OAUTH_CALLBACK_URL);
        final String uri = liToken.getAuthorizationUrl();
        getSharedPreferences(OAUTH_PREF, MODE_PRIVATE).edit()
                .putString(PREF_REQTOKENSECRET, liToken.getTokenSecret())
                .commit();


         Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
         startActivity(i);
    }


void finishAuthenticate(final Uri uri) {
        if (uri != null && uri.getScheme().equals(OAUTH_CALLBACK_SCHEME)) {
            final String problem = uri.getQueryParameter(OAUTH_QUERY_PROBLEM);
            if (problem == null) {
                final SharedPreferences pref = getSharedPreferences(OAUTH_PREF,
                        MODE_PRIVATE);
                final LinkedInAccessToken accessToken = oAuthService
                        .getOAuthAccessToken(
                                new LinkedInRequestToken(uri
                                        .getQueryParameter(OAUTH_QUERY_TOKEN),
                                        pref.getString(PREF_REQTOKENSECRET,
                                                null)),
                                uri.getQueryParameter(OAUTH_QUERY_VERIFIER));
                pref.edit()
                        .putString(PREF_TOKEN, accessToken.getToken())
                        .putString(PREF_TOKENSECRET,
                                accessToken.getTokenSecret())
                        .remove(PREF_REQTOKENSECRET).commit();
                showCurrentUser(accessToken);
            } else {
                Toast.makeText(this,
                        "Appliaction down due OAuth problem: " + problem,
                        Toast.LENGTH_LONG).show();
                finish();
            }

        }
    }


void clearTokens() {
        getSharedPreferences(OAUTH_PREF, MODE_PRIVATE).edit()
                .remove(PREF_TOKEN).remove(PREF_TOKENSECRET)
                .remove(PREF_REQTOKENSECRET).commit();
    }

    void showCurrentUser(final LinkedInAccessToken accessToken) {

        final LinkedInApiClient client = factory
                .createLinkedInApiClient(accessToken);
        try {

            final Person profile = client.getProfileForCurrentUser(EnumSet.of(
                    ProfileField.ID, ProfileField.FIRST_NAME,
                    ProfileField.LAST_NAME, ProfileField.HEADLINE,
                    ProfileField.INDUSTRY, ProfileField.PICTURE_URL,
                    ProfileField.DATE_OF_BIRTH, ProfileField.LOCATION_NAME,
                    ProfileField.MAIN_ADDRESS, ProfileField.LOCATION_COUNTRY
                    ));

            // /////////////////////////////////////////////////////////
            // here you can do client API calls ...
            // client.postComment(arg0, arg1);
            // client.updateCurrentStatus(arg0);
            // or any other API call (this sample only check for current user
            // and shows it in TextView)
            // /////////////////////////////////////////////////////////


            System.out.println("p => " + profile);
            System.out.println("PersonID : " + profile.getId());
            System.out.println("Name : " + profile.getFirstName() + " "
                    + profile.getLastName());
            System.out.println("Headline : " + profile.getHeadline());
            System.out.println("Industry : " + profile.getIndustry());
            System.out.println("Picture : " + profile.getPictureUrl());
            DateOfBirth dateOfBirth = profile.getDateOfBirth();
            System.out.println("DateOfBirth : " + dateOfBirth.getDay() + "/"
                    + dateOfBirth.getMonth() + "/" + dateOfBirth.getYear());
            System.out.println("MAin Address : " + profile.getMainAddress());
            Location location = profile.getLocation();
            System.out.println("Location:" + location.getName() + " - "
                    + location.getCountry().getCode());
            // get_from_last


            Toast.makeText(LITestActivity.this, "Wait...", Toast.LENGTH_LONG).show();



            startActivity(new Intent(LITestActivity.this,
                    UserProfileScreen.class)
                    .putExtra("get_from_last", "1")
                    .putExtra("getId", profile.getId())
                    .putExtra("getEmail", "[email protected]")
                    .putExtra("getFirstName", profile.getFirstName())
                    .putExtra("getLastName", profile.getLastName())
                    .putExtra("getHeadline", profile.getHeadline())
                    .putExtra("getPictureUrl", profile.getPictureUrl())
                    .putExtra(
                            "dob",
                            dateOfBirth.getDay() + "/" + dateOfBirth.getMonth()
                                    + "/" + dateOfBirth.getYear()));

            finish();
        } catch (LinkedInApiClientException ex) {
            clearTokens();
            Toast.makeText(
                    this,
                    "Appliaction down due LinkedInApiClientException: "
                            + ex.getMessage()
                            + " Authokens cleared - try run application again.",
                    Toast.LENGTH_LONG).show();
            pd.dismiss();
            finish();
        }

    }

    int i = 0;

    public void onNewIntent(Uri intent) {

        if (i == 0) {
            i++;
            finishAuthenticate(intent);
        } else {
            i++;
        }
        System.out.println("i => " + i);
    }

but i m stuck how to get email address so can any one help me

Subscapular answered 23/5, 2013 at 9:26 Comment(0)
C
17

Even though its an old question, I think its worth to answer. I struggled a lot to find a way to fetch user email address from linkedin using linkedin-j-android library. Unfortunately I could not find any ready to use solution, so I made changes in the library sources and re-packaged it to use in my app. You can download the library from this link: https://dl.dropboxusercontent.com/u/46373731/linkedin-j-android.jar

You can use ProfileField.EMAIL_ADDRESS to fetch email-address.

Coruscation answered 24/7, 2013 at 20:32 Comment(4)
How can i get the contact number ?Nickell
still it gives me null for email address. Here is my code try { profile = client.getProfileForCurrentUser(EnumSet.of( ProfileField.ID, ProfileField.FIRST_NAME, ProfileField.EMAIL_ADDRESS, ProfileField.LAST_NAME )); Log.e("create access token secret", client.getAccessToken() .getTokenSecret()); Log.i("email...","."+ProfileField.EMAIL_ADDRESS); } catch (NullPointerException e) { // TODO: handle exception }Incommodity
you cannot share i.e. post to wall through this jarTuque
Hi @deepak4bin, this does not work for me, any idea why?Organize

© 2022 - 2024 — McMap. All rights reserved.