1

我正在尝试使用以下代码对 google 进行身份验证,但 google 再次将我发送回登录页面

//STEP# 1
                string loginURL = "https://www.google.com/accounts/ServiceLoginBox?service=analytics&nui=1&hl=en-US&continue=https%3A%2F%2Fwww.google.com%2Fanalytics%2Fsettings%2F%3Fet%3Dreset%26hl%3Den%26et%3Dreset%26hl%3Den-US";
                request = (HttpWebRequest)WebRequest.Create(loginURL);
                request.CookieContainer = cookieJar;
                request.Method = "GET";             
                request.KeepAlive = true;
                request.UserAgent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/2008111217 Fedora/3.0.4-1.fc10 Firefox/3.0.4";


                HttpWebResponse response = (HttpWebResponse)request.GetResponse();


                foreach (Cookie cook in response.Cookies)
                {
                      cookieJar.Add(cook);
                }


                using (StreamReader sr = new StreamReader(response.GetResponseStream()) )
                {
                    serverResponse = sr.ReadToEnd();                       
                    sr.Close();
                }           

                galx = ExtractValue(serverResponse,"GALX","name=\"GALX\" value=\"");

                Console.WriteLine(galx);


                //Request# 2

                string uriWithData = "https://www.google.com/accounts/ServiceLoginBoxAuth";
                request = (HttpWebRequest)WebRequest.Create(uriWithData);
                request.KeepAlive = true;
                request.UserAgent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/2008111217 Fedora/3.0.4-1.fc10 Firefox/3.0.4";
                request.Method = "POST";
                request.CookieContainer = cookieJar;
                string param = string.Format("Email={0}&Passwd={1}&continue={2}&service=analytics&nui=1&dsh=8209101995200094904&GALX={3}&hl=en-US&PersistentCookie=yes","**my email address**",p,"",galx);
                byte[] postArr = StrToByteArray(param);
                request.ContentType = @"application/x-www-form-urlencoded"; 
                request.ContentLength = param.Length;

                Stream reqStream = request.GetRequestStream();
                reqStream.Write(postArr,0,postArr.Length);
                reqStream.Close();

                response = (HttpWebResponse)request.GetResponse();


                foreach (Cookie cook in response.Cookies)
                {
                      cookieJar.Add(cook);
                }


                using (StreamReader sr = new StreamReader(response.GetResponseStream()) )
                {
                    serverResponse = sr.ReadToEnd();

                    Console.WriteLine(serverResponse);
                    // Close and clean up the StreamReader       
                    sr.Close();
                }           
4

2 回答 2

0

尝试查看谷歌帐户 apiGBaseService。我相信你将不得不像马蒂HOSTED_OR_GOOGLE这篇文章accountType中所做的那样做好准备。

于 2010-03-19T13:25:59.957 回答
0

我不知道,我很确定没有多少人会想要筛选那么多代码。

我一眼就看到可能导致问题的一件事是你玩cookies太多了。

创建一个 CookieContainer 并将其与每个请求一起传递。

无需“转移”或“重新创建”容器。

于 2010-03-19T12:42:13.517 回答