2012-08-07 40 views
0

我不知道如果我失去了一些東西,但我只是不能檢索來自谷歌的cPanel共享聯繫人!?谷歌的cPanel - 檢索所有共享聯繫人

auth令牌由第一請求返回,但下一個返回HTTP/1.1 401 Unknown authorization header

文檔:

https://developers.google.com/google-apps/domain-shared-contacts/

代碼:

// Authentication 
$post_data = array(
    'accountType' => 'HOSTED', 
    'Email' => '[email protected]', 
    'Passwd' => 'password', 
    'service' => 'cp', 
    'source' => 'the_source' 
); 
$post = http_build_query($post_data); 
$fp = fsockopen('ssl://www.google.com', 443, $errno, $errstr, 20); 
$header = "POST /accounts/ClientLogin HTTP/1.1\\r\n". 
    "Host: www.google.com\r\n". 
    "Content-Type: application/x-www-form-urlencoded\r\n". 
    "Content-Length: ".strlen($post)."\r\n". 
    "Connection: Close\r\n\r\n".$post; 
fwrite($fp, $header); 
$auth_response = ''; 
while($line = fgets($fp)){ 
    $auth_response .= $line; 
} 
fclose($fp); 

list($header, $content) = explode("\r\n\r\n", $auth_response); 
preg_match('/\sauth=(.*)\s/i', $content, $matches); 
$auth_token = $matches[1]; 

// Retrieve contacts 
$response = ''; 
$fp = fsockopen('ssl://www.google.com', 443, $errno, $errstr, 20); 
$write = "GET /m8/feeds/contacts/my_domain/full HTTP/1.1\r\n". 
    "Host: www.google.com\r\n". 
    "Authorization: [email protected] token=\"$auth_token\"\r\n". 
    "Content-Type: application/x-www-form-urlencoded\r\n\r\n". 
    "Connection: Close\r\n\r\n"; 
fwrite($fp, $write); 
while($line = fgets($fp)){ 
    $response .= $line; 
} 
fclose($fp); 
echo $response; 

回答

0

ClientLogin文檔指出AUTH頭應該是:

Authorization: GoogleLogin auth=yourAuthToken 
+0

它仍然無法正常工作 – clarkk 2012-08-08 07:38:07