2012-09-09 3 views
0

Google API 콘솔 https://code.google.com/apis/console을 활성화했으며 OAuth 자격증 명을 포함하여 프로젝트를 만들었습니다. 이 응용 프로그램은 브라우저 외부에서 실행되기 때문에 "데스크톱 응용 프로그램"설정을 선택했습니다. (실제로는 내 컴퓨터에만 해당).명령 줄에서 Google 캘린더 액세스

여기에 설명 된대로 클라이언트 라이브러리도 다운로드했습니다 : https://code.google.com/p/google-api-php-client/.

내가 키 application_name, oauth2_client_id, oauth2_client_secret, oauth2_redirect_urideveloper_key 및 아무것도 편집 google-api-php-client/src/config.php을 편집했습니다.

다른 서비스도 모두 services에서 삭제했습니다.

지금, 나는 다음과 같은 응용 프로그램은, 가이드의 샘플에서 조립 있습니다

나는 다음과 같은 오류 받고 있어요 그러나
<?php 
require_once 'google-api-php-client/src/apiClient.php'; 
require_once "google-api-php-client/src/contrib/apiCalendarService.php"; 

session_start(); 

$apiClient = new apiClient(); 
$apiClient->setUseObjects(true); 
$service = new apiCalendarService($apiClient); 


if (isset($_SESSION['oauth_access_token'])) { 
    $apiClient->setAccessToken($_SESSION['oauth_access_token']); 
} else { 
    $token = $apiClient->authenticate(); 
    $_SESSION['oauth_access_token'] = $token; 
} 

$event = new Event(); 
$event->setSummary('Appointment'); 
$event->setLocation('Somewhere'); 
$start = new EventDateTime(); 
$start->setDateTime('2011-06-03T10:00:00.000-07:00'); 
$start->setTimeZone('America/Los_Angeles'); 
$event->setStart($start); 
$end = new EventDateTime(); 
$end->setDateTime('2011-06-03T10:25:00.000-07:00'); 
$end->setTimeZone('America/Los_Angeles'); 
$event->setEnd($end); 
$event->setRecurrence(array('RRULE:FREQ=WEEKLY;UNTIL=20110701T100000-07:00')); 
$attendee1 = new EventAttendee(); 
$attendee1->setEmail('attendeeEmail'); 
// ... 
$attendees = array($attendee1, 
        // ... 
        ); 
$event->attendees = $attendees; 
$recurringEvent = $service->events->insert('primary', $event); 

echo $recurringEvent->getId(); 

:

Fatal error: Uncaught exception 'apiServiceException' with message 'Error calling POST https://www.googleapis.com/calendar/v3/calendars/primary/events?key=<the-key>: (401) Login Required' in /home/flav/projects/.../google-api-php-client/src/io/apiREST.php on line 86 

apiServiceException: Error calling POST https://www.googleapis.com/calendar/v3/calendars/primary/events?key=<the-key>: (401) Login Required in /home/flav/projects/.../google-api-php-client/src/io/apiREST.php on line 86 

Call Stack: 
    0.0003  252600 1. {main}() /home/flav/projects/.../gcal-api.php:0 
    0.0202 1769344 2. EventsServiceResource->insert() /home/flav/projects/.../gcal-api.php:38 
    0.0202 1770288 3. apiServiceResource->__call() /home/flav/projects/.../google-api-php-client/src/contrib/apiCalendarService.php:493 
    0.0206 1781864 4. apiREST::execute() /home/flav/projects/.../google-api-php-client/src/service/apiServiceResource.php:187 
    0.2342 1794848 5. apiREST::decodeHttpResponse() /home/flav/projects/.../google-api-php-client/src/io/apiREST.php:56 

방법이 문제를 해결하는가?

아, 그리고 구글의 API 콘솔에, 나는 하나의 내가 oauth2_redirect_uri 사용해야 Redirect URIs:, urn:ietf:wg:oauth:2.0:oobhttp://localhost에 대한 두 개의 값을 가지고?

답변

0

나는 이것이 여러 가지 원인에 의해 발생할 수 있다고 생각합니다. 내 2 센트 :

여러 개의 캘린더가 등록되어 있습니까? 어쩌면 이벤트를 삽입하려는 캘린더가 "기본"(기본?) 캘린더가 아니거나 Oauth 신용 데이터가 다른 캘린더를 참조하는 것일 수도 있습니다. 그렇다면 ... 달력 아이디 찾기가 조금 어렵

$calendar_id = "[email protected]"; //look this up from calendar /settings calendar details settings page at the bottom 
$service->events->insert($calendar_id, $event); 

와 함께이 라인

$service->events->insert('primary', $event); 

교체를 찾아보십시오. 예를 들어, Google 계정 홈 페이지/캘린더/톱니 바퀴 아이콘/설정/하단의 캘린더 이름/캘린더 세부 정보 설정 페이지를 클릭하면 찾을 수 있습니다.

리디렉션 URL (웹 앱의 경우)은 oauth 요청을 발행 한 .php 페이지를 가리 킵니다. 인증 된 경우 다른 리디렉션을 정의합니다. 이번에는 내 자신입니다. 혼란스러워? 네,하지만 저에게는 효과가 있습니다.