我尝试使用Gmail登录身份验证使用网络视图登录我的应用程序,当我使用模拟器运行时总是显示网页不可用。请找到附带的屏幕截图。我不明白这是怎么来的,请任何正文建议我如何获取gmail登录身份验证和用户令牌。 提前致谢 这是我的代码。
<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;
}
这里我附加了屏幕截图![网页不可用]
答案 0 :(得分: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