15

I'm having some trouble connecting to the Linkedin API.

I'm following this https://developer.linkedin.com/docs/android-sdk and this https://developer.linkedin.com/docs/android-sdk-auth, yet I'm getting this error code:

{
"errorCode": "INVALID_REQUEST",
"errorMessage": "either bundle id or package name \/ hash are invalid, unknown, malformed"
}

My implementation so far is pretty simple:

public void shareOnLinkedin() {

    AuthListener authListener = new AuthListener() {
        @Override
        public void onAuthSuccess() {
            Log.d(TAG, "Success");
        }

        @Override
        public void onAuthError(LIAuthError error) {
            Log.d(TAG, error.toString());
        }
    };

    LISessionManager
            .getInstance(getApplicationContext())
            .init(ColectionDetailActivity.this, buildScope(), authListener, true);
}

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

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

    try {
        LISessionManager.getInstance(getApplicationContext())
                .onActivityResult(this, requestCode, resultCode, data);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
FeleMed
  • 601
  • 9
  • 28

2 Answers2

2

Make sure you've added all you package hashes correctly in your LinkedIn Developer Console.

Generating a debug key hash value


It's under Mobile and would look like this,

App's Package that will be using the LinkedIn SDK: com.mypackage.app

Generated package hash: /i17lYLZpSffk1wdD+KzlRJroZU=

deubaka
  • 1,447
  • 12
  • 22
  • This was done according to the documentation, yet still does not connect correctly. – FeleMed Sep 08 '15 at 00:39
  • Make sure to add all the key hashes: the debug.keystore of all the developers on your team, as well as your release keystore. Just make sure that your app is signed with the same keystore (which a has was generated) has been added to LinkedIn's Developer Console. – deubaka Sep 09 '15 at 02:24
  • Thank you for your reply. Actually I have added the has and the package name according to the documentation, which is actually the same step of configuration you have to do with the facebook SDK, and it's using the same PackageName and Hash, yet I still get that error. – FeleMed Sep 09 '15 at 14:53
  • Did you forward the values on your `onActivityResult` to `LISessionManager`'s `onActivityResult` as well? – deubaka Sep 10 '15 at 07:27
  • Yes, I've updated the code in the original question. Actually I checked the sampleapp from Linkedin and it's actually quite similar to my code. I think the issue is in the hash, but I don't why this hash would work in Facebook SDK. – FeleMed Sep 10 '15 at 23:34
  • @Heyyou Because when I execute the script that's in the documentation it generates the same key (keytool -exportcert -keystore ~/.android/debug.keystore -alias androiddebugkey | openssl sha1 -binary | openssl base64). – FeleMed Sep 11 '15 at 18:55
  • 1
    @Heyyou yeah I went through them, but all seems to look OK. As an update I creted a release version with a release hash for Facebook SDK and Linkedin SDK and it keeps working in Facebook but not in Linkedin, so pretty much this is a dead end. – FeleMed Sep 12 '15 at 20:11
  • @FeleMed any luck with this? – Dan Dinu Nov 18 '17 at 17:48
1

I had the same issue, after implementing fb login i started implementing LinkedIn Login and added the same hash which i got it for fb login and it didn't work.

I did the following in order to fix the issue.

For Release Hash:

  1. Run this command on your release apk to print all the certificate

    keytool -list -printcert -jarfile <your apk path>
    
  2. Copy the SHA1 value Go to http://tomeko.net/online_tools/hex_to_base64.php and convert your SHA1 hex value to Base64

  3. The value i got is different from the value i got from regular release keystore command.

added hash in linked in dashboard and its started working.

Note: if anyone has idea why regular keystore method fails and why this one works please let me know.

This is for Debug Hash:

The above method will work for the debug apk too. but this is how i got the hash for debug apk and it's different from given keystore command.

private void getTokenInfo() {

    try {
        PackageInfo info = getPackageManager().getPackageInfo(
                "your package name here",
                PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());

            Logger.d("packageName", info.packageName);
            Logger.d("hash", Base64.encodeToString(md.digest(), Base64.NO_WRAP));

        }
    } catch (PackageManager.NameNotFoundException e) {
        Logger.e(e);
    } catch (NoSuchAlgorithmException e) {
        Logger.e(e);
    }
}

This is working for me and i yet to understand whats happening here.

Irfan
  • 956
  • 9
  • 16