Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why I can't login with Linkedin android sdk?

I tried to login with LinkedIn sdk, but it didn't work. I have a button, and I write into the onClick method this:

if (view.getId() == btnLinkedinLogin.getId()){
        LISessionManager.getInstance(getActivity()).init(getActivity(), Scope.build(Scope.R_FULLPROFILE), new AuthListener() {
            @Override
            public void onAuthSuccess() {
                Log.d(TAG, "succesful linkedin login");
                ((MainActivity)getActivity()).showFragment("Tile");
            }

            @Override
            public void onAuthError(LIAuthError error) {
                Log.d(TAG, "failed linkedin login. Error: " + error.toString());
            }
        }, false);
    }

I override the onActivityResult method like this:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    LISessionManager.getInstance(getActivity().getApplicationContext()).onActivityResult(getActivity(), requestCode, resultCode, data);
   // super.onActivityResult(requestCode, resultCode, data);
}

But if I running my app and click on the login button, the linkedin logo is showing, but after it will be hidden and my application don't call the AuthListener methods...

I have already create my linkedin app and set the package name and hash value.

I see in the log this: request is https://www.linkedin.com/uas/mobilesdk/authorize scope=r_fullprofile&duid=5770a1bf-2567-4fd1-9358-b762856df6d3&packageName=com.beee&packageHash=8dRCxNsk3LZTTd11iJmoiYaCpIA%3D&csrfToken=ajax%3A1829388572167379991&userAuthorized=false

UPDATE: I checked my linkedin profile and i saw my linkedin application in my profile. If I remove this, and try to login again, now i see the screen where linkedin app need premissions, but after it not calling any method...

like image 647
just Avatar asked Jul 14 '15 07:07

just


1 Answers

It doesn't seem like the SDK supports calls from a Fragment (which I am assuming you are doing since you call getActivity()). I ran into the same issue and had to workaround it using a listener interface and having the parent activity make the calls to LISessionManager.init().

You could also add this bit of code to your onActivityResult() method in order to read the contents of the result, which may be useful in determining whether or not your request is running into errors.

@Override
public void onActivityResult(
    int requestCode,
    int resultCode,
    Intent data
) {
        Bundle bundle = data.getExtras();
        Set<String> setKeys = bundle.keySet();
        for (String sKey : setKeys) {
            Log.d(
                TAG, String.format("Extra: (%s:%s)", sKey, bundle.get(sKey).toString()
            );
        }
        // Rest of your code
}
like image 83
sven Avatar answered Oct 09 '22 15:10

sven