我看到几个关于如何登录谷歌的问题,但所有的答案都是关于身份验证和谷歌 API 的。我想要一个简单的谷歌登录,只是为了检查用户是否存在(我不打算对用户帐户做任何事情(访问电子邮件等......)。用户在点击时填写电子邮件和密码通过http连接记录的登录按钮完成。问题是,即使我输入了错误的电子邮件或密码,它也会继续记录。我不知道我是否使用错误的谷歌网站登录或什么。
这是函数调用和谷歌登录网站:
new LoginIntoGoogle().execute(new String[] {"https://accounts.google.com/ServiceLogin?"});
这就是代码正在做的事情:
private class LoginIntoGoogle extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... url) {
// Start HTTP connection and send the database to the web server
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url[0]);
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("Email", ""+userEmail));
nameValuePairs.add(new BasicNameValuePair("Passwd", ""+passtext.getText().toString().trim()));
nameValuePairs.add(new BasicNameValuePair("signIn", "Login"));
// Execute HTTP Post Request
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
if (response.getStatusLine().getStatusCode() < 300 && response.getStatusLine().getStatusCode() >= 200) {
System.out.println(response.getStatusLine().getStatusCode());
Editor editor = mPrefs.edit();
editor.putString("login_status", "Logged into your google account");
editor.commit();
return "Logged into your google account";
}
else {
Editor editor = mPrefs.edit();
editor.putString("login_status", "Problem to login into your google account");
editor.commit();
return "Problem to login into your google account";
}