2014-09-28 75 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