代码之家  ›  专栏  ›  技术社区  ›  steven

通过谷歌应用程序登录

  •  2
  • steven  · 技术社区  · 16 年前

    我还需要访问他们的电子邮件。

    我读过需要Oauth,但我不知道这是否正确。

    我在用PHP。

    1 回复  |  直到 16 年前
        1
  •  0
  •   Richard June    16 年前

    我在我写的一个库中使用这个代码从gmail中提取联系信息。 http://www.oriontechnologysolutions.com/programming/libgoog_php 这个特定的函数将验证一个帐户并传回一个用于访问Google服务的Auth令牌。

        function login() {
            $response = Array();
            if(isset($this->domain))
                $email = $this->username . '@' . $this->domain;
            else
                $email = $this->username;
            $requestString = "service=".$this->service."&Email=".urlencode($email)."&Passwd=".urlencode($this->passwd)."&source=".self::source;
    
            $c = curl_init();
            curl_setopt($c, CURLOPT_URL, self::loginUrl);
            curl_setopt($c, CURLOPT_POST,   1);
            curl_setopt($c, CURLOPT_POSTFIELDS, $requestString);
            curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    
            $res = curl_exec($c);
            $httpCode = curl_getinfo($c, CURLINFO_HTTP_CODE);
            foreach(explode("\n", $res) as $line) {
                if(strpos($line, "=") != false) {
                    gooDebug("Exploding $line\n", 4);
                    list($name, $value) = explode("=", $line);
                    $response[$name] = $value;
                }
            }
            if($httpCode !=200)
                return($response);
    
            $this->authTok = $response['Auth'];
            return($this->authTok);
        }
    
    推荐文章