douba4275 2019-02-04 10:20
浏览 72

我可以使用Google API授权服务帐户嵌入日历iframe吗?

I am trying to embed a Google Calendar in an iframe using the embed code with the calendar id. I have created a service account and granted this account access to the calendar in question.

I can succesfully authenticate the service account using the google api client, and I can fetch the events from the calendar. However, I cannot figure out how to authenticate so I can show the 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>`

The result is simply a message telling me that I am not allowed to show the calendar in question.

  • 写回答

1条回答 默认 最新

  • douchiwan1503 2019-02-04 11:19
    关注

    What you appear to be doing

    <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>
    

    Would be like you trying to run the google calendar application in an iframe. Thats not going to work as there would be no way for you to authenticate it and i dont think that google will allow their login from an iframe.

    What you should be doing

    You should take your application design the calendar display as you wish and then place your application in an iframe.

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

    A service account is just going to give you access to the data its not going to give you access to run the google calendar website via an iframe.

    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line