Linkedin Android SDK - Unable to connect to API (INVALID_REQUEST)
Asked Answered
T

2

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();
    }
}
Toddtoddie answered 6/9, 2015 at 22:56 Comment(2)
may be system time issue.. check your mobile time..Dasilva
Same issue here, can't get this to work nor find anything useful :-(.Savonarola
D
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=

Dell answered 7/9, 2015 at 3:20 Comment(8)
This was done according to the documentation, yet still does not connect correctly.Toddtoddie
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.Dell
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.Toddtoddie
Did you forward the values on your onActivityResult to LISessionManager's onActivityResult as well?Dell
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.Toddtoddie
@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).Toddtoddie
@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.Toddtoddie
@Toddtoddie any luck with this?Brightness
I
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.

Ignacioignacius answered 19/7, 2018 at 10:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.