2012-08-07 4 views
0

Google 캘린더에서 공유 주소록을 검색 할 수 없습니까?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' => '[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 문서가 인증 헤더를 명시 다음과 같아야합니다.

Authorization: GoogleLogin auth=yourAuthToken 
+0

여전히 작동하지 않습니다. – clarkk