【问题标题】:Google Calendar API in production生产中的 Google 日历 API
【发布时间】:2020-09-23 15:23:15
【问题描述】:

请问有没有人可以回答我有关 Google Calendar API 的问题?我已经生成了凭据,并且在本地主机上它工作得很好。我只想返回 100 个即将发生的事件($service->events->listEvents($calendarId, $optParams) 但生产中的相同代码不起作用,它返回 500 Internal Server Error 特别是在这段代码上。任何建议如何继续?

这是一段代码,它在第一个注释行中断

<?php

require './vendor/autoload.php';

$client = new Google_Client();
$gazza = new GuzzleHttp\Client([
    'verify' => './cacert.pem'
]);
$client->setApplicationName('Google Calendar API PHP Quickstart');
$client->setScopes(Google_Service_Calendar::CALENDAR_READONLY);
$client->setAuthConfig('./credentials-calendar-old.json');
$client->setAccessType('offline');

$tokenPath = 'token.json';
if (file_exists($tokenPath)) {
    $accessToken = json_decode(file_get_contents($tokenPath), true);
    $client->setAccessToken($accessToken);
}

$service = new Google_Service_Calendar($client);

$calendarId = 'primary';
$optParams = array(
    'maxResults' => 1000,
    'orderBy' => 'startTime',
    'singleEvents' => true,
    'timeMin' => date('c'),
);

$results = $service->events->listEvents($calendarId, $optParams);
$events = $results->getItems();

// Print the next 10 events on the user's calendar.
$calendarId = 'primary';
$optParams = array(
    'maxResults' => 1000,
    'orderBy' => 'startTime',
    'singleEvents' => true,
    'timeMin' => date('c'),
);

非常感谢,

亚历克斯

【问题讨论】:

  • 这篇文章需要更多信息,500服务器错误意味着函数以崩溃结束。崩溃可能是从类型错误到调用外部服务的错误,你需要找到你的代码被破坏的地方。
  • 我发布了一段代码,给我 500 的 URL 是 www.pedagogickydiar.com/kalendar
  • 您的代码中有错误:[错误] 视口参数键“minimal-ui”无法识别和忽略。 (日历,第 1 行)[错误] TypeError:null 不是对象(评估'document.getElementById('ypembedcontainer').style')yp_emb_resp_check(yp_r_iframe.js:9)全局代码(yp_r_iframe.js:13)[错误] 未处理的承诺拒绝:语法错误:字符串与预期的模式不匹配。 (匿名函数) promiseReactionJob [Error] TypeError: null is not an object (evalating 'document.getElementById('ypembedcontainer').style') yp_emb_resp_check (yp_r_iframe.js:9)

标签: google-calendar-api


【解决方案1】:

尝试删除下面的代码,据我所知,此代码仅适用于 localhost,以强制 https。

$gazza = new GuzzleHttp\Client([
    'verify' => './cacert.pem'
]);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-21
    • 2020-06-25
    • 1970-01-01
    • 2020-12-27
    • 1970-01-01
    相关资源
    最近更新 更多