• Модуль: webdav
  • Путь к файлу: ~/bitrix/modules/webdav/classes/editdocgoogle.php
  • Класс: CWebDavEditDocGoogle
  • Вызов: CWebDavEditDocGoogle::downloadFile
public function downloadFile(array $fileData)
{
	$accessToken = $this->getAccessToken();
	$id = $fileData['id'];
	$mimeType = $fileData['mimeType'];
	@set_time_limit(0);
	$http = new CHTTP();
	$http->http_timeout = 10;
	$http->SetAdditionalHeaders(array(
		"Authorization" => "Bearer {$accessToken}",
	));
	if(!$http->GET('https://www.googleapis.com/drive/v2/files/' . $id))
	{
		return false;
	}
	// access token expired, let's get a new one and try again
	if ($http->status == "401")
	{
		//todo: invalid credential response
		return false;
	}

	// error checking
	if ($http->status != "200")
	{
		return false;
	}

	$file = json_decode($http->result, true);
	$links = $file['exportLinks'];
	$link = empty($links[$mimeType])? '' : $links[$mimeType];
	if(!$link)
	{
		$link = $file['downloadUrl'];
	}

	$http = new CHTTP();
	$http->http_timeout = 10;
	$http->SetAdditionalHeaders(array(
		"Authorization" => "Bearer {$accessToken}",
	));
	if(!$http->GET($link))
	{
		return false;
	}
	$file['content'] = $http->result? $http->result:'';
	CWebDavTools::convertFromUtf8($file['title']);
	$file['name'] = $file['title'];

	$this->recoverExtensionInName($file, $mimeType);

	return $file;
}