2010-03-28 65 views
2

如何通過我們的Google Apps帳戶驗證我的用戶身份? 我也需要訪問他們的電子郵件。通過Google Apps登錄

我讀過Oauth,但我不知道這是否正確。

我正在使用PHP。

回答

0

我在我寫的一個庫中使用這段代碼來從gmail提取聯繫信息。 http://www.oriontechnologysolutions.com/programming/libgoog_php。 此特定功能將驗證一個帳戶並傳回用於訪問Google服務的驗證令牌。

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); 
    }