Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Oren Tuchin
28,529 PointsHas anyone successfully completed a LInkedIn Oauth2 API Integration via Native Android App's webview?
I have the basics down of setting up the webview to make the initial request, but do not know how to block the redirect using shouldOverrideUrlLoading, and bring everything back into the Activity, while also retrieving the token and user profile. My xml is just a full screen webview. I'm not sure if anything else is needed since I want to redirect to a different activity ("ProfilePage"). I have tried using the following within shouldOverrideUrlLoading:
Intent intent = new Intent(X, ProfilePage.class); startActivity(intent);
but get an error when I try using Context or an Activity for X.
Any code help would be appreciated. Note that Linkedin requires a redirect URL that begins with "https://" so redirecting back into the app from them is not possible. I have tried using the following to get to successfully get to the first step in the authorization process (note that google.com is just a generic placeholder for the redirect URL since I don't actually intend to go there):
public class LinkedInSignIn extends Activity {
private WebView wv1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.linkedin_signin);
wv1 = (WebView) findViewById(R.id.webview);
wv1.setWebViewClient(new MyBrowser());
wv1.getSettings().setLoadsImagesAutomatically(true);
wv1.getSettings().setJavaScriptEnabled(true);
wv1.loadUrl("https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id="my_private_ID_from_LinkedIn"&redirect_uri==https%3A%2F%2Fwww.google.com&scope=r_basicprofile");
}
private class MyBrowser extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}