【问题标题】:Add event to my Google Calendar using PHP API使用 PHP API 将事件添加到我的 Google 日历
【发布时间】:2018-08-02 08:46:56
【问题描述】:

我知道有很多与此相关的问题,我已经尝试了 2-3 天,但没有任何成功。

我的网页中有一个日历,用户可以在其中选择日期和时间,然后单击一个按钮,该条目将在我的(所有者)Google 日历中创建,无需任何身份验证。我已经将我的 Google 日历设为公开。这是我的代码:

require_once __DIR__ . '/google-api-php-client-2.2.1/vendor/autoload.php';
$DEVELOPER_KEY = 'some-key-here';
$client = new Google_Client();
$client->setDeveloperKey($DEVELOPER_KEY);
$calendar = new Google_Service_Calendar_Calendar();
$event = new Google_Service_Calendar_Event(array(
  'summary' => 'Google I/O 2015',
  'location' => '800 Howard St., San Francisco, CA 94103',
  'description' => 'A chance to hear more about Google\'s developer products.',
  'start' => array(
    'dateTime' => '2018-05-28T09:00:00-07:00',
    'timeZone' => 'America/Los_Angeles',
  ),
  'end' => array(
    'dateTime' => '2018-05-28T17:00:00-07:00',
    'timeZone' => 'America/Los_Angeles',
  ),
  'recurrence' => array(
    'RRULE:FREQ=DAILY;COUNT=2'
  ),
  'attendees' => array(
    array('email' => 'lpage@example.com'),
    array('email' => 'sbrin@example.com'),
  ),
  'reminders' => array(
    'useDefault' => FALSE,
    'overrides' => array(
      array('method' => 'email', 'minutes' => 24 * 60),
      array('method' => 'popup', 'minutes' => 10),
    ),
  ),
));

$calendarId = 'someid@gmail.com';
$event = $calendar->events->insert($calendarId, $event);
printf('Event created: %s\n', $event->htmlLink);

当我运行它时,我得到了错误

Fatal error: Call to a member function insert() on null

我在哪里犯了错误,或者我错过了什么?请帮忙。

【问题讨论】:

  • 下面的答案正确吗?看起来您可能已经使用答案中给出的代码更新了问题,但没有遵循确认正确答案或解决方案,这让其他人感到沮丧。
  • @DylanGlockler 这不是我的问题的正确解决方案,你还想让我检查它是否正确,因为它让其他人感到沮丧??
  • 不,在这种情况下没有意义,很抱歉造成混乱。

标签: google-calendar-api


【解决方案1】:

我认为$calendar = new Google_Service_Calendar_Calendar(); 应该是$calendar = new Google_Service_Calendar();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-10
    • 2019-07-03
    • 1970-01-01
    • 2011-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-24
    相关资源
    最近更新 更多