Jon*_*ett 29 oauth google-calendar-api google-api
我一直在研究Google Calendar API和有关身份验证的文档(http://code.google.com/apis/calendar/v3/using.html#auth).这里提到的用例似乎是编写一个访问用户日历的应用程序.但是,我正在编写一个网页,该网页将访问网站所有者的日历并仅显示该日历的信息.因此,我不希望用户输入他们的Google帐户信息,这是oAuth想要做的事情.
基本上,我正在寻找一种方法来访问单个私有Google日历,并通过将凭据直接传递给服务来对其进行身份验证.
这里有一个类似的问题:如何使用OAuth与Google日历仅访问一个日历? 这似乎表明海报最初是直接传递凭证.此功能是否仍然可用?你如何处理我描述的用例?
gX.*_*gX. 16
如果我没错,他们现在已启动服务帐户:https://developers.google.com/accounts/docs/OAuth2ServiceAccount
编辑:
这是他们的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(...)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
36132 次 |
最近记录: |