2014-08-28 68 views
0

我一直在試用instagram API。我不明白爲什麼授權頁面不會加載到我的webview中。其他網頁,如雅虎和谷歌正確加載。一些網頁不能在android的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

也許你需要啓用JavaScript的:

loginView.getSettings().setJavaScriptEnabled(true); 
相關問題