Visual C#:连接到Google帐户

时间:2011-06-03 10:43:06

标签: c# connection account

我正在尝试连接我的Google帐户并获取我的博客主页的html代码。我发现需要一个cookie来保持连接,但我不知道怎么做。

用户名和密码的发布地址为“https://www.google.com/accounts/ClientLogin”

提前致谢!

2 个答案:

答案 0 :(得分:1)

试试这个

private bool Authorize(out string authCode)
{
    bool result = false;
    authCode = "";

    string queryString = String.Format("https://www.google.com/accounts/ClientLogin?accountType=HOSTED_OR_GOOGLE&Email={0}&Passwd={1}&service=cloudprint&source={2}", UserName, Password, Source);
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(queryString);

    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    string responseContent = new StreamReader(response.GetResponseStream()).ReadToEnd();

    string[] split = responseContent.Split('\n');
    foreach (string s in split)
    {
        string[] nvsplit = s.Split('=');
        if (nvsplit.Length == 2)
        {
            if (nvsplit[0] == "Auth")
            {
                authCode = nvsplit[1];
                result = true;
            }
        }
    }

    return result;
}

`

答案 1 :(得分:0)

Google Code Playground有一些如何做事的好例子。 Here's an example如何从博客中检索帖子。希望它有所帮助。