Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linkedin Android SDK - Unable to connect to API (INVALID_REQUEST)

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();
    }
}
like image 444
FeleMed Avatar asked Sep 06 '15 22:09

FeleMed


2 Answers

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=

like image 162
deubaka Avatar answered Nov 18 '22 10:11

deubaka


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.

like image 1
Irfan Avatar answered Nov 18 '22 12:11

Irfan