我一直在试用Instagram API。我不明白为什么授权页面没有加载到我的webview中。其他网页,如雅虎和谷歌正确加载。
这是我的代码
public class LogInFragment extends Fragment {
private static final String AUTHURL = "https://api.instagram.com/oauth/authorize/";
public static String CALLBACKURL = "https://www.google.com";
private static final String CLIENT_ID = "02c86b5fe4a648a0a6a47966a7bac9cb";
public LogInFragment() {
// TODO Auto-generated constructor stub
Log.d("LogInFragment", "Fragment Created");
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_login, container, false);
Log.d("LogInFragment", "In onCreateView");
String auth_URL = AUTHURL + "?client_id="+CLIENT_ID+"&redirect_uri="+CALLBACKURL+"&response_type=code";
WebView loginView = (WebView) view.findViewById(R.id.loginWV);
loginView.setWebViewClient(new authWebViewClient());
loginView.loadUrl(auth_URL);
Log.d("LogInFragment", auth_URL);
return view;
}
private class authWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
if (url.startsWith(CALLBACKURL)) {
Log.d("LogInFragment", "CALLBACK called");
Intent intent = new Intent(getActivity(),MainActivity.class);
String[] urlPart = url.split("=");
String code = urlPart[1];
intent.putExtra("code", code);
startActivity(intent);
}
Log.d("LogInFragment", "CALLBACK notcalled");
return true;
}
}
答案 0 :(得分:0)
也许您需要启用javascript:
loginView.getSettings().setJavaScriptEnabled(true);