Android: LinkbackIn OAuth Callback not working

I am using LinkedIn OAuth in my Android app. I already have a LinkedIn application, a consumer key and a secret, as a result I can request a successful execution.

Everything is fine until there is a callback. The web page is not chime, I mean onNewIntent or onResume methods that do not call. The web page only displays the callback address with the parameters. I mean, it looks like this:

 callback_url://?oauth_token=324sdf&oath_verifier=as21dsf 

Here is my code:

 try { consumer = new CommonsHttpOAuthConsumer("ConsumerKey", "ConsumerSecret"); provider = new CommonsHttpOAuthProvider("https://api.linkedin.com/uas/oauth/requestToken", "https://api.linkedin.com/uas/oauth/accessToken", "https://api.linkedin.com/uas/oauth/authorize"); final String url = provider.retrieveRequestToken(consumer, Constants.OAUTH_CALLBACK_URL); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)).setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_FROM_BACKGROUND); startActivity(intent); } catch (Exception e) { e.printStackTrace(); } 

Activity is already defined as singleInstance in Manifest .

What is wrong or not?

+6
source share
1 answer

I found the answer myself after a long study.

I changed the base class to linkedin-j , which can be viewed here here .

Then set these constants as shown below:

  public static final String CONSUMER_KEY = "ConsumerKey"; public static final String CONSUMER_SECRET = "ConsumerSecret"; public static final String OAUTH_CALLBACK_SCHEME = "callback"; public static final String OAUTH_CALLBACK_URL = OAUTH_CALLBACK_SCHEME + ":///"; 

And initialize like this:

 LinkedInOAuthService oAuthService = LinkedInOAuthServiceFactory.getInstance().createLinkedInOAuthService(Constants.CONSUMER_KEY, Constants.CONSUMER_SECRET); LinkedInApiClientFactory factory = LinkedInApiClientFactory.newInstance(Constants.CONSUMER_KEY, Constants.CONSUMER_SECRET); LinkedInRequestToken liToken; LinkedInApiClient client; liToken = oAuthService.getOAuthRequestToken(Constants.OAUTH_CALLBACK_URL); Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(liToken.getAuthorizationUrl())); startActivity(i); 

This callback is good, and I turned to OnNewIntent:

 String verifier = intent.getData().getQueryParameter("oauth_verifier"); LinkedInAccessToken accessToken = oAuthService.getOAuthAccessToken(liToken, verifier); client = factory.createLinkedInApiClient(accessToken); client.postNetworkUpdate("Test"); 

What all.

+2
source

Source: https://habr.com/ru/post/921305/


All Articles