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_uri
및 developer_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:oob
및 http://localhost
에 대한 두 개의 값을 가지고?