我尝试使用服务帐户在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:无起始行'在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();
答案 0 :(得分:0)
如果 google-api-php-client / agentbranding -... p12 是真正的文件名(我的意思是点数),我建议
$key_file_location = dirname(__FILE__).'/google-api-php-client/agentbranding-..........p12';