如何使用PHP将事件插入用户谷歌日历?

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了如何使用PHP将事件插入用户谷歌日历?脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我有以下代码插入我的特定谷歌日历.它非常成功,但如何让用户可以@L_777_3@到自己的日历?有人可以帮助我…我的预期结果就像用户可以通过谷歌登录….这意味着用户可以添加到他们自己的谷歌日历.谢谢.

添加到我的特定日历的代码

require_once './vendor/GOOGLE/apiclient/src/Google/autoload.PHP';

$key_file_location = 'Calendar-96992da17e2dda.p12'; // key.p12 to create in the Google Api console

$client_id = '6094969424649-compute@develoPEr.gserviceaccount.COM';
$service_account_name = 'testsd-440@studied-zephyr-117012.iam.gserviceaccount.com'; // Email Address in the console account

if (strpos($client_id,"gserviceaccount") == false || !strlen($service_account_name) || !strlen($key_file_location)) {
    echo "no credentials were set.";
    exIT;
}

/** We create service access ***/
$client = new Google_Client();  

/************************************************
If we have an access token,we can carry on.  (Otherwise,we'll get one with the help of an  assertion credential.)
Here we have to list the scopes manually. We also supply  the service account
 ************************************************/
if (isset($_SESSION['service_token'])) {
        $client->setAccessToken($_SESSION['service_token']);
}
$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
    $service_account_name,array('https://www.googleapis.com/auth/calendar'),// ou calendar_readonly
$key
);

$client->setAssertionCredentials($cred);
if ($client->getAuth()->isAccessTokenExpired()) {
    $client->getAuth()->refreshTokenWithAssertion($cred);
}
$_SESSION['service_token'] = $client->getAccessToken();



// Get the API client and construct the service object.
$service = new Google_Service_Calendar($client);


    /************* INSERT ****************/
$event = new Google_Service_Calendar_Event(array(
  'summary' => 'My Summary','location' => 'My Location','description' => 'My Description','start' => array(
    'dateTime' => '2015-12-31T09:09:00','timeZone' => 'Asia/Singapore',),'end' => array(
    'dateTime' => '2015-12-31T17:16:00','attendees' => array(
    array('email' => 'abc@gmail.com'),array('email' => 'def@gmail.my'),'reminders' => array(
    'useDefault' => FALSE,'overrides' => array(
      array('method' => 'email','minutes' => 24 * 60),array('method' => 'popup','minutes' => 10),));

$events = $service->events->insert('Primary',$event);
PRintf('Event created: %s',$events->htMLLink);
使用PHP client library.
// Refer to the PHP quickstart on how to SETUP the environment:
// https://developers.google.com/google-apps/calendar/quickstart/PHP
// Change the scope to Google_Service_Calendar::CALENDAR and delete any Stored
// credentials.

$event = new Google_Service_Calendar_Event(array(
  'summary' => 'Google I/O 2015','location' => '800 Howard St.,San Francisco,CA 94103','description' => 'A chance to hear more about Google\'s developer products.','start' => array(
    'dateTime' => '2015-05-28T09:00:00-07:00','timeZone' => 'America/Los_Angeles','end' => array(
    'dateTime' => '2015-05-28T17:00:00-07:00','recurrence' => array(
    'RRULE:FREQ=DAILY;COUNT=2'
  ),'attendees' => array(
    array('email' => 'lpage@example.com'),array('email' => 'sbrin@example.com'),));

$calendarId = 'primary';
$event = $service->events->insert($calendarId,$event);
printf('Event created: %s\n',$event->htmlLink);

有关详细信息,请查看此处的官方文档Events: insert

脚本宝典总结

以上是脚本宝典为你收集整理的如何使用PHP将事件插入用户谷歌日历?全部内容,希望文章能够帮你解决如何使用PHP将事件插入用户谷歌日历?所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。