【问题标题】:Can I use Google API to authorize a service account to embed calendar iframe?我可以使用 Google API 授权服务帐户嵌入日历 iframe 吗?
【发布时间】:2019-02-04 10:20:25
【问题描述】:

我正在尝试使用带有日历 ID 的嵌入代码在 iframe 中嵌入 Google 日历。我创建了一个服务帐户并授予此帐户访问相关日历的权限。

我可以使用 google api 客户端成功验证服务帐户,并且可以从日历中获取事件。但是,我不知道如何进行身份验证,所以我可以显示 iframe。

require_once __DIR__ . '/googleapi/vendor/autoload.php';
$client = new Google_Client();

$client->setApplicationName('Google Calendar API PHP');
$client->setScopes(Google_Service_Calendar::CALENDAR_READONLY);
$client->setAuthConfig('my-credentials.json');
$client->setAccessType('offline');
$service = new Google_Service_Calendar($client);

?>
<iframe src="https://calendar.google.com/calendar/embed?src=calendarId&ctz=Europe%2FCopenhagen" style="border: 0" width="800" height="600" frameborder="0" scrolling="no"></iframe>`

结果只是一条消息,告诉我不允许我显示有问题的日历。

【问题讨论】:

    标签: php iframe google-calendar-api google-api-php-client


    【解决方案1】:

    你在做什么

    <iframe src="https://calendar.google.com/calendar/embed?src=calendarId&ctz=Europe%2FCopenhagen" style="border: 0" width="800" height="600" frameborder="0" scrolling="no"></iframe>
    

    就像您尝试在 iframe 中运行 google 日历应用程序一样。那是行不通的,因为您无法对其进行身份验证,而且我认为 google 不会允许他们从 iframe 登录。

    你应该做什么

    您应该按照自己的意愿设计日历显示,然后将您的应用程序放在 iframe 中。

    <iframe src="https://yourcalendar.application.dk/awsomapp.php" style="border: 0" width="800" height="600" frameborder="0" scrolling="no"></iframe>
    

    服务帐户只会让您访问数据,而不会让您访问通过 iframe 运行 google 日历网站。

    【讨论】:

      猜你喜欢
      • 2018-09-03
      • 2013-08-21
      • 2020-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-03
      • 2014-11-21
      相关资源
      最近更新 更多