2014-09-28 193 views
0

我试图登录我的应用程序使用Gmail登录身份验证使用Web视图时,当我运行使用模拟器总是显示网页不可用。请找到所附的屏幕shoot.I不明白这是怎么来的,请任何机构建议我如何获得gmail登录身份验证和用户令牌。 在此先感谢 这是我的代码。错误Gmail登录OAuth android使用webview

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context=".MainActivity" > 

    <WebView 
      android:id="@+id/webview" android:layout_width="fill_parent" 
      android:layout_height="fill_parent" /> 

</RelativeLayout> 

public class MainActivity extends Activity { 
    WebView webview; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

      webview = (WebView)findViewById(R.id.webview); 
      webview.getSettings().setJavaScriptEnabled(true); 

      String OAUTH_URL ="https://accounts.google.com/o/oauth2/auth"; 
      String REDIRECT_URI="http://localhost"; 
      String ACCESS_TYPE = "offline"; 
      String RESPONSE_TYPE = "code"; 
      String OAUTH_SCOPE="https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.profile.emails.read https://www.googleapis.com/auth/userinfo.email https://www.google.com/m8/feeds"; 
      String CLIENT_ID = "";//confidential 
      String REQUEST = OAUTH_URL+"?redirect_uri="+REDIRECT_URI+"&response_type="+RESPONSE_TYPE+"&client_id="+CLIENT_ID+"&scope="+OAUTH_SCOPE+"&access_type="+ACCESS_TYPE; 

      webview.setWebViewClient(new WebViewClient() { 

       @Override 
       public void onPageStarted(WebView view, String url,Bitmap bitmap) { 

        System.out.println("onPageStarted url->"+url); 
       } 
       @Override 
       public void onPageFinished(final WebView view, final String url) { 
        System.out.println("onPage finished url->"+url); 

        /*if (url.startsWith(Constants.OAUTH2PARAMS.getRederictUri())) { 
         webview.setVisibility(View.INVISIBLE); 

         if (!handled) { 
          new ProcessToken(url,oAuth2Helper).execute(); 
         } 
        } else { 
         webview.setVisibility(View.VISIBLE); 
        }*/ 
       } 

      }); 

      webview.loadUrl(REQUEST); 

    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 

这里的IAM连接的屏幕截图![网页不是即时拍摄]

回答

0
[Here][1] is a perfect example. 


    [1]: http://tush.wordpress.com/2014/07/15/android-google-contact-api-3-0-example/ 

Use the authentication process from this example. 

And also in your code clientID is blank it can't be empty for debug mode it should 
be empty for only release mode of your application