我不知道我是否遗漏了某些内容,但我无法从Google 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' => 'my_email@gmail.com',
'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: my_email@gmail.com 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;