Rasmus B
Rasmus B

Reputation: 51

Can I use Google API to authorize a service account to embed calendar 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.

Upvotes: 2

Views: 286

Answers (1)

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 117271

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.

Upvotes: 1

Related Questions