2

특정 사용자에게 PHP를 통해 캘린더 이벤트를 생성하려고합니다. 예를 들어 [email protected]입니다.서비스 계정 인증

Google Developers Console에 서비스 계정을 만들고 ClientID, 전자 메일 주소 및 개인 키를 받았습니다. 인증은 코드로 수행됩니다.

$client = new Google_Client(); 
if (isset($_SESSION['service_token'])) { 
    $client->setAccessToken($_SESSION['service_token']); 
} 
$cred = new Google_Auth_AssertionCredentials(
    '[email protected]', 
    array('https://www.googleapis.com/auth/calendar','https://www.googleapis.com/auth/calendar.readonly'), 
    file_get_contents('p12 file')); 
$client->setAssertionCredentials($cred); 
if ($client->getAuth()->isAccessTokenExpired()) { 
    $client->getAuth()->refreshTokenWithAssertion($cred); 
} 
$_SESSION['service_token'] = $client->getAccessToken(); 

이 인증 유형은 꽤 괜찮은 것으로 보입니다. 그러나 모든 이벤트는 [email protected] 대신 전자 메일 주소 [email protected]을 사용하여 사용자로 만들어집니다.

나는 하위 매개 변수를 설정 시도했다 :

$cred = new Google_Auth_AssertionCredentials(
.... 
$cred->sub = '[email protected]'; 
$client->setAssertionCredentials($cred); 

는하지만이 코드 조각은 예외가 발생합니다 :

Google_Auth_Exception: Error refreshing the OAuth2 token, message: '{ "error" : "access_denied", "error_description" : "Requested client not authorized." }' 

을 그리고 지금은 잃었어요. 어떤 충고?

답변

3

확인, ;-)

문제는 자신의 도메인에 developement에와 있었다 해결.

other questionGoogle SDK Guide에서 언급했듯이 범위에 서비스 계정에 대한 액세스 권한을 부여해야합니다. 액세스 권한을 요청합니다. 읽기 전용 범위를 추가하는 것을 잊어 버렸습니다.