0

我不知道我是否遗漏了什么,但我无法从 Google cpanel 检索共享联系人!?

身份验证令牌由第一个请求返回,但下一个返回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;
4

1 回答 1

0

ClientLogin文档声明 auth 标头应该是:

Authorization: GoogleLogin auth=yourAuthToken
于 2012-08-07T12:24:11.803 回答