• Модуль: calendar
  • Путь к файлу: ~/bitrix/modules/calendar/lib/sync/googleapitransport.php
  • Класс: BitrixCalendarSyncGoogleApiTransport
  • Вызов: GoogleApiTransport::__construct
public function __construct($userId)
{
	if (!Loader::includeModule('socialservices'))
	{
		throw new SystemException("Can not include module "SocialServices"! " . __METHOD__);
	}

	$this->client = new WebHttpClient();
	if (RequestLogger::isEnabled())
	{
		$this->requestLogger = new RequestLogger((int)$userId, self::SERVICE_NAME);
	}

	if (CSocServGoogleProxyOAuth::isProxyAuth())
	{
		$oAuth = new CSocServGoogleProxyOAuth($userId);
	}
	else
	{
		$oAuth = new CSocServGoogleOAuth($userId);
	}

	$oAuth->getEntityOAuth()->addScope(
		[
			'https://www.googleapis.com/auth/calendar',
			'https://www.googleapis.com/auth/calendar.readonly',
		]
	);
	$oAuth->getEntityOAuth()->setUser($userId);
	if ($oAuth->getEntityOAuth()->GetAccessToken())
	{
		$this->client->setHeader('Authorization', 'Bearer ' . $oAuth->getEntityOAuth()->getToken());
		$this->client->setHeader('Content-Type', 'application/json');
		$this->client->setHeader('Referer', $this->getDomain());
		unset($oAuth);
	}
	else
	{
		$this->errors[] = array("code" => "NO_ACCESS_TOKEN", "message" => "No access token found");
	}
}