【问题标题】:Google calendar integration with html static form on localhostGoogle 日历与本地主机上的 html 静态表单集成
【发布时间】: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


    【解决方案1】:

    如果 google-api-php-client/agentbranding-..........p12 是真正的文件名(我的意思是点),我建议

    $key_file_location = dirname(__FILE__).'/google-api-php-client/agentbranding-..........p12';
    

    【讨论】:

    • 但是错误依然存在。这是真正的文件。请帮我配置这个日历。
    • 谢谢,您提供的错误日志质疑“p12”证书文件的有效性。我提出了一种解决文件位置的解决方案。如果它是 Linux 服务器(正斜杠),这应该可以工作,是吗?
    • @MuhammadSohaib 不过,agentbranding-.......p12 看起来不像是一个有效的文件名。
    • 我已经开发了自己的谷歌日历应用,你可以在postbrain.com,postbrain.com/calendar看到它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多