1

I just followed “https://developer.linkedin.com/docs/android-sdk” for integrating linked sdk in my app. the steps that i have done in my app such as,

  1. Download linkedin library for mobile
  2. Import it in my app as library
  3. Get Key hash code
  4. Create a application inside linkedin developer console
  5. Configured package name & Package hash

After then everything is working fine in my app. that means i am able to access profile details from linkedin(debuggable case). but the problem is i am not able to login when i build the released apk.

Added release key inside linkedin developer app. for mac i just used the below command to get release key in terminal,

keytool -exportcert -keystore MY_RELEASE_KEY_PATH -alias MY_RELEASE_KEY_ALIAS | openssl sha1 -binary | openssl base64

Here is my Activity code:

public void login(View view) {
        LISessionManager.getInstance(getApplicationContext())
                .init(this, buildScope(), new AuthListener() {
                    @Override
                    public void onAuthSuccess() {
                        APIHelper apiHelper = APIHelper.getInstance(getApplicationContext());
           apiHelper.getRequest(MainActivity.this, topCardUrl, new ApiListener() {
                @Override                         

                public void onApiSuccess(ApiResponse s) {

                 Log.e(TAG, "Profile json" + s.getResponseDataAsJson());
                 Log.e(TAG, "Profile String" + s.getResponseDataAsString());

                   try {
                     Log.e(TAG, "Profile emailAddress" + s.getResponseDataAsJson().get("emailAddress").toString());
                     Log.e(TAG, "Profile formattedName" + s.getResponseDataAsJson().get("formattedName").toString());

                     txtFirstName.setText(s.getResponseDataAsJson().get("emailAddress").toString());
                     txtLastName.setText(s.getResponseDataAsJson().get("formattedName").toString()); 

                     Picasso.with(MainActivity.this).load(s.getResponseDataAsJson().getString("pictureUrl"))
                            .into(imgProfilePic);

                        }catch (Exception e){

                        }

              }

                @Override 

                public void onApiError(LIApiError error) {
                            //((TextView) findViewById(R.id.response)).setText(error.toString());                            Toast.makeText(getApplicationContext(), "Profile failed " + error.toString(),
                                    Toast.LENGTH_LONG).show();
                        }
                    });

                }


                    @Override
                    public void onAuthError(LIAuthError error) {
                        Toast.makeText(getApplicationContext(), "failed " + error.toString(),
                                Toast.LENGTH_LONG).show();

                    }
                }, true);
    }

    private static Scope buildScope() {
        return Scope.build(Scope.R_BASICPROFILE, Scope.R_EMAILADDRESS);
    }

    @Override
    protected void onActivityResult(int requestCode,
                                    int resultCode, Intent data) {

        LISessionManager.getInstance(getApplicationContext())
                .onActivityResult(this,
                        requestCode, resultCode, data);
    }

Everytime i am getting the below error while click on signin with linkedinbutton in my app.

Error={
"errorCode": "UNKNOWN_ERROR"
    }
pb123
  • 489
  • 3
  • 9
  • 25

2 Answers2

1

Attach your keystore.jks file to your project (if you are working with android studio), follow this and realted answers.

Then generate your Key Hash by the giving code.

private void genertaeHashKey() {
        Log.d("DEBUG", "Generating Hash Key");
        try
        {
            PackageInfo info = getPackageManager().getPackageInfo(
                    getPackageName(), PackageManager.GET_SIGNATURES);
            for (Signature signature : info.signatures) {
                MessageDigest md = MessageDigest.getInstance("SHA");
                md.update(signature.toByteArray());
                Log.e("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
            }

        } catch (PackageManager.NameNotFoundException e) {
            Log.e("KeyHash:", "" + e);
            Toast.makeText(SplashScreenActivity.this, e.toString(), Toast.LENGTH_SHORT).show();
        } catch (NoSuchAlgorithmException e)

        {
            Log.e("KeyHash:", "" + e);
        }
    }

then register your Key Hash on the linkedin developer console. It did work for me. Hope it will help you.

Ajeet Choudhary
  • 1,969
  • 1
  • 17
  • 41
0

Have you changed Build Variants debug to release ?

Paddy02
  • 71
  • 2
  • 11
  • Follow this step: keytool -exportcert -keystore MY_RELEASE_KEY_PATH -alias MY_RELEASE_KEY_ALIAS | openssl sha1 -binary | openssl base64 – pb123 Sep 17 '17 at 10:01