How to connect to Google Calendar API without oAuth authentication?

I studied the Google Calendar API and authentication documents ( http://code.google.com/apis/calendar/v3/using.html#auth ). It seems that the use case mentioned here is an application that accesses the user's calendar. However, I am writing a web page that will have access to the calendar of the website owner and display only one calendar information. Therefore, I do not want the user to enter information about his Google account, which he wants to do.

Basically, I'm looking for a way to access one private Google calendar and authenticate by passing credentials directly to the service.

There are similar questions here: How do I use OAuth with Google Calendar to access only one calendar? which seems to indicate that the poster originally transmitted credentials directly. Is this feature available? How do you handle your use case?

+29
source share
3 answers

. 3 , , . -
-, ( ), .
, REST.

google api php client, . google-api-php-client/src/config.php , , . - script, .

+11

, : https://developers.google.com/accounts/docs/OAuth2ServiceAccount

Edit:

Prediction API

session_start();
require_once "google-api-php-client/src/Google_Client.php";
require_once "google-api-php-client/src/contrib/Google_CalendarService.php";

const CLIENT_ID = '...';
const SERVICE_ACCOUNT_NAME = '...';

// Make sure you keep your key.p12 file in a secure location, and isn't
// readable by others.
const KEY_FILE = '...';

$client = new Google_Client();
$client->setApplicationName("...");


if (isset($_SESSION['token'])) {
 $client->setAccessToken($_SESSION['token']);
}

// Load the key in PKCS 12 format (you need to download this from the
// Google API Console when the service account was created.
$key = file_get_contents(KEY_FILE);
$client->setAssertionCredentials(new Google_AssertionCredentials(
    SERVICE_ACCOUNT_NAME,
    array('https://www.googleapis.com/auth/calendar', "https://www.googleapis.com/auth/calendar.readonly"),
    $key)
);

$client->setClientId(CLIENT_ID);
$service = new Google_CalendarService($client);

//Save token in session
if ($client->getAccessToken()) {
  $_SESSION['token'] = $client->getAccessToken();
}

//And now you can use the code in their PHP examples, like: $service->events->listEvents(...)
+15

:

https://github.com/googleapis/google-api-php-client#authentication-with-service-accounts

After creating the service account, you can authenticate without inviting the user to add items to the calendar that your service owns.

0
source

All Articles