I am trying to use Oauth2 in an Android app to get authentication token from Reddit api. I am just trying to use Reddit api from my Android app and it is a must to use Oauth2 to achieve that. In my app, webview is being used to navigate user to following page.
If user clicks Allow, the app would receive authorization code from Reddit so that it can make api requests to the Reddit api. As you can see from above, the url that navigate user to above page works on desktop chrome browser. In the Android simulator, however, I can see the loading page on reddit from webview but the webview suddenly disappers with following error on Logcat:
"Access to XMLHttpRequest at 'https://events.redditmedia.com/v1?key=Mweb3&mac=469c6ed7767c9980560cd23847c8cb8ce021cae472cf4d440ec700b45b926f2d' from origin 'https://www.reddit.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource."
When creating reddit app for Oauth2, I selected "installed app". Following is the url that I am using:
This is the code I am using for webview:
web.loadUrl(url);
web.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
Log.i("","page started");
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
My webview works fine for other urls but not this one for some reason I guess. I would much appreciate if anyone could take a look. Thank you in advance!