Calendar 如何访问任何其他';使用google php api创建google日历

Calendar 如何访问任何其他';使用google php api创建google日历,calendar,google-calendar-api,google-api-php-client,Calendar,Google Calendar Api,Google Api Php Client,我需要使用google php api访问任何其他用户的google日历freebusy。有谁能帮助我一步一步地实现这一点。我已经检查过了,但没有结果 我的方法 但我在忙与闲方面越来越空白了 只需确保日历是公共的,然后尝试google calendar freebusy方法。这肯定会奏效的 你能分享你的尝试吗?@LaurIvan谢谢你的关注。我已经添加了我的代码,请检查它,如果可能,请向我建议任何解决方案。@DalmTo代码运行良好,当我登录并尝试获取freebusy时,它会显示正确的数据。但我

我需要使用google php api访问任何其他用户的google日历freebusy。有谁能帮助我一步一步地实现这一点。我已经检查过了,但没有结果

我的方法
但我在忙与闲方面越来越空白了

只需确保日历是公共的,然后尝试google calendar freebusy方法。这肯定会奏效的

你能分享你的尝试吗?@LaurIvan谢谢你的关注。我已经添加了我的代码,请检查它,如果可能,请向我建议任何解决方案。@DalmTo代码运行良好,当我登录并尝试获取freebusy时,它会显示正确的数据。但我的要求是不同的,我需要其他人的空闲忙碌的日历id(电子邮件id)和时间最小,最大。这次显示空结果。我希望这对你有帮助。可能有点傻,但是。。。你确定你有权查看其他人的日历吗?@LaurIvan实际上他们会通过登录一次来批准我的申请,然后只有我可以访问。你能给我一些建议吗。
session_start();

require_once ('libraries/Google/autoload.php');

$client = new Google_Client();
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->addScope("email");
$client->addScope("profile");
$client->addScope(Google_Service_Calendar::CALENDAR);
$client->addScope(Google_Service_Calendar::CALENDAR_READONLY);
$client->setAccessType('offline'); 

$service = new Google_Service_Oauth2($client);

if (isset($_GET['code'])) {
  $client->authenticate($_GET['code']);
  $_SESSION['access_token'] = $client->getAccessToken();
  header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
  exit;
}

/************************************************
  If we have an access token, we can make
  requests, else we generate an authentication URL.
 ************************************************/
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
  $client->setAccessToken($_SESSION['access_token']);
} else {
  $authUrl = $client->createAuthUrl();
}

$client->setApplicationName("My Calendar"); //DON'T THINK THIS MATTERS
$client->setDeveloperKey($api_key); //GET AT AT DEVELOPERS.GOOGLE.COM
$cal = new Google_Service_Calendar($client);
$calendarId = 'any_other_user_email@gmail.com';

$freebusy_req = new Google_Service_Calendar_FreeBusyRequest();

$freebusy_req->setTimeMin($minTime);
$freebusy_req->setTimeMax($maxTime);
$freebusy_req->setTimeZone($time_zone);
$freebusy_req->setCalendarExpansionMax(10);
$freebusy_req->setGroupExpansionMax(10);

$item = new Google_Service_Calendar_FreeBusyRequestItem();
$item->setId($email);

$freebusy_req->setItems(array($item));

$query = $cal->freebusy->query($freebusy_req);

$response_calendar = $query->getCalendars();
$busy_obj = $response_calendar[$email]->getBusy();