【发布时间】:2016-02-14 13:06:13
【问题描述】:
我正在尝试使用服务帐户在 Google 日历上创建条目。我真的很接近这一点。
运行时出现以下错误:
警告:file_get_contents() 期望参数 1 是有效路径,字符串在 D:\wamp\www\calendar-test\google-api-php-client\src\Google\Signer\P12.php 中给出54
致命错误:未捕获的异常“Google_Auth_Exception”带有消息“无法解析 p12 文件。这是一个 .p12 文件吗?密码是否正确? OpenSSL 错误:错误:0906D06C:PEM 例程:PEM_read_bio:no start line' in D:\wamp\www\calendar-test\google-api-php-client\src\Google\Signer\P12.php 第 56 行
Google_Auth_Exception:无法解析 p12 文件。这是一个 .p12 文件吗?密码是否正确? OpenSSL 错误:错误:0906D06C:PEM 例程:PEM_read_bio:第 56 行的 D:\wamp\www\calendar-test\google-api-php-client\src\Google\Signer\P12.php 中没有起始行
require_once "google-api-php-client/src/Google/autoload.php";
require_once "google-api-php-client/src/Google/Client.php";
require_once "google-api-php-client/src/Google/Service/Calendar.php";
//obviously, insert your own credentials from the service account in the Google Developer's console
$client_id = '1014261369752...........';
$service_account_name = 'agentbranding@appspot.gserviceaccount.com';
$key_file_location = 'google-api-php-client/agentbranding-..........p12';
//echo $key_file_location;
if (!strlen($service_account_name) || !strlen($key_file_location))
echo missingServiceAccountDetailsWarning();
$client = new Google_Client();
$client->setApplicationName("Agent Branding Appointment");
if (isset($_SESSION['service_token'])) {
$client->setAccessToken($_SESSION['service_token']);
}
$key = file_get_contents($key_file_location);
$client->setClientId($client_id);
$client->setAssertionCredentials(new Google_Auth_AssertionCredentials(
$service_account_name, 'https://www.google.com/calendar/feeds/........6mp0df4@group.calendar.google.com/private/full/',
$key)
);
$client->setClientId($client_id);
$calendarService = new Google_Service_Calendar($client);
$calendarList = $calendarService->calendarList;
//Set the Event data
$event = new Google_Service_Calendar_Event();
$event->setSummary('Today Big Event');
$event->setDescription('Big Event Dedcription');
$start = new Google_Service_Calendar_EventDateTime();
$start->setDateTime('2016-02-17T17:00:00-07:00');
$event->setStart($start);
$end = new Google_Service_Calendar_EventDateTime();
$end->setDateTime('2016-02-18T17:00:00-07:00');
$event->setEnd($end);
$createdEvent = $calendarService->events->insert('$cal_id', $event);
echo $createdEvent->getId();
【问题讨论】:
标签: php