Failed to get LinkedIn account login screen. linking my app to LinkedIn

I was trying to integrate Login LInkedIn from my android app. I've searched so far, but there are limited examples on how to do this. but one great answer from this question Sending a LinkedIn message from an Android app gave me a head start.

but when i run it. it takes me to the login screen and then when I enter my credentials and click Login and Allow it does something in the browser but nothing happens. it doesn't register and return to my application.

Here is my code:

final SharedPreferences pref = getSharedPreferences(OAUTH_PREF,
                MODE_PRIVATE);
        final String token = pref.getString(PREF_TOKEN, null);
        final String tokenSecret = pref.getString(PREF_TOKENSECRET, null);
        if (token == null || tokenSecret == null) {
            new AsyncTask<Void, Void, LinkedInRequestToken>() {

                @Override
                protected LinkedInRequestToken doInBackground(Void... params) {
                    return oAuthService.getOAuthRequestToken(OAUTH_CALLBACK_URL);
                }

                @Override
                protected void onPostExecute(LinkedInRequestToken liToken) {
                    final String uri = liToken.getAuthorizationUrl();
                    getSharedPreferences(OAUTH_PREF, MODE_PRIVATE)
                            .edit()
                            .putString(PREF_REQTOKENSECRET,
                                    liToken.getTokenSecret()).commit();
                    Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
                    startActivity(i);
                }
            }.execute();
        } else {
            showCurrentUser(new LinkedInAccessToken(token, tokenSecret));
        }final LinkedInOAuthService oAuthService = LinkedInOAuthServiceFactory
                .getInstance().createLinkedInOAuthService(CONSUMER_KEY,
                        CONSUMER_SECRET);

      

//////////////////////////// ESTIMATE CODE //////////////////

    void finishAuthenticate(final Uri uri) {
    if (uri != null && uri.getScheme().equals(OAUTH_CALLBACK_SCHEME)) {
        final String problem = uri.getQueryParameter(OAUTH_QUERY_PROBLEM);
        if (problem == null) {

            new AsyncTask<Void, Void, LinkedInAccessToken>() {

                @Override
                protected LinkedInAccessToken doInBackground(Void... params) {
                    final SharedPreferences pref = getSharedPreferences(
                            OAUTH_PREF, MODE_PRIVATE);
                    final LinkedInAccessToken accessToken = oAuthService
                            .getOAuthAccessToken(
                                    new LinkedInRequestToken(
                                            uri.getQueryParameter(OAUTH_QUERY_TOKEN),
                                            pref.getString(
                                                    PREF_REQTOKENSECRET,
                                                    null)),
                                    uri.getQueryParameter(OAUTH_QUERY_VERIFIER));
                    pref.edit()
                            .putString(PREF_TOKEN, accessToken.getToken())
                            .putString(PREF_TOKENSECRET,
                                    accessToken.getTokenSecret())
                            .remove(PREF_REQTOKENSECRET).commit();
                    return accessToken;
                }

                @Override
                protected void onPostExecute(LinkedInAccessToken accessToken) {
                    showCurrentUser(accessToken);
                }
            }.execute();

        } else {
            Toast.makeText(this,
                    "Appliaction down due OAuth problem: " + problem,
                    Toast.LENGTH_LONG).show();
            finish();
        }

    }
}

void clearTokens() {
    getSharedPreferences(OAUTH_PREF, MODE_PRIVATE).edit()
            .remove(PREF_TOKEN).remove(PREF_TOKENSECRET)
            .remove(PREF_REQTOKENSECRET).commit();
}
void showCurrentUser(final LinkedInAccessToken accessToken) {
    final LinkedInApiClient client = factory
            .createLinkedInApiClient(accessToken);

    new AsyncTask<Void, Void, Object>() {

        @Override
        protected Object doInBackground(Void... params) {
            try {

                final Person p = client.getProfileForCurrentUser();
                // /////////////////////////////////////////////////////////
                // here you can do client API calls ...
                // client.postComment(arg0, arg1);
                // client.updateCurrentStatus(arg0);
                // or any other API call
                // (this sample only check for current user
                // and pass it to onPostExecute)
                // /////////////////////////////////////////////////////////
                return p;
            } catch (LinkedInApiClientException ex) {
                return ex;
            }
        }

        @Override
        protected void onPostExecute(Object result) {
            if (result instanceof Exception) {
                //result is an Exception :)
                final Exception ex = (Exception) result;
                clearTokens();
                Toast.makeText(
                        getApplicationContext(),
                        "Appliaction down due LinkedInApiClientException: "
                                + ex.getMessage()
                                + " Authokens cleared - try run application again.",
                        Toast.LENGTH_LONG).show();
                finish();
            } else if (result instanceof Person) {
                final Person p = (Person) result;
                Toast.makeText(
                        getApplicationContext(),p.getLastName() + ", " + p.getFirstName(),
                        Toast.LENGTH_LONG).show();
            }
        }
    }.execute();

}

      

//// END LOG OF MY APP IS ///////////

08-23 12:31:34.010  32724-32728/com.example.montovaapp D/-heap﹕ GC_CONCURRENT freed 251K, 5% free 8598K/9031K, paused 12ms+154ms, total 221ms

08-23 12:31:35.790  32724-32728/com.example.montovaapp D/-heap﹕ GC_CONCURRENT freed 857K, 12% free 8231K/9287K, paused 12ms+156ms, total 215ms

08-23 12:31:37.290  32724-32728/com.example.montovaapp D/-heap﹕ GC_CONCURRENT freed 261K, 10% free 8383K/9287K, paused 12ms+33ms, total 69ms

08-23 12:31:39.410  32724-32728/com.example.montovaapp D/-heap﹕ GC_CONCURRENT freed 255K, 9% free 8526K/9287K, paused 12ms+14ms, total 50ms

08-23 12:31:43.160  32724-32724/com.example.montovaapp W/IInputConnectionWrapper﹕ showStatusIcon on inactive InputConnection

      

Just note that programming using Android Studio

considers

+3


source to share


1 answer


Sorry, but maybe using ASNE library and asne-linkedin to make your life easier? Just add a dependency on your project:

dependencies {
...
    compile 'com.github.asne:asne-linkedin:0.2.0'
...
}

      

set up and request a login, for example



socialNetwork.requestLogin();

      

And you can easily add another social network or other request ...

+2


source







All Articles