[英]How to simple login on Google via HTTP connection with Android?
我看到有關如何登錄Google的幾個問題,但所有答案都涉及身份驗證和Google API。 我想要在Google上進行簡單的登錄,只是為了檢查用戶是否存在(我不打算使用用戶帳戶執行任何操作(訪問電子郵件等)。當用戶單擊時,填寫電子郵件和密碼通過http連接登錄完成登錄按鈕的問題是,即使我輸入了錯誤的電子郵件或密碼,它也會繼續記錄。我不知道我是否使用了錯誤的Google網站登錄或登錄了什么。
這是函數調用和google登錄網站:
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";
}
您必須使用加密,因為您正在通過Internet傳輸個人數據。
你應該看int Oauth
查看最近發布的Google Playstore服務。 閱讀文檔 。 觀看Google IO關於PlayStore服務的視頻 。
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.