- Модуль: webdav
- Путь к файлу: ~/bitrix/modules/webdav/classes/editdocgoogle.php
- Класс: CWebDavEditDocGoogle
- Вызов: CWebDavEditDocGoogle::insertPermission
public function insertPermission(array $fileData)
{
$accessToken = $this->getAccessToken();
$fileId = $fileData['id'];
$http = new CHTTP();
$http->http_timeout = 10;
$arUrl = $http->ParseURL("https://www.googleapis.com/drive/v2/files/{$fileId}/permissions");
$http->SetAdditionalHeaders(array(
"Authorization" => "Bearer {$accessToken}",
));
$postFields = "{"role":"writer", "type":"anyone", "withLink":true, "value": null}";
$postContentType = 'application/json; charset=UTF-8';
if(!$http->Query('POST', $arUrl['host'], $arUrl['port'], $arUrl['path_query'], $postFields, $arUrl['proto'], $postContentType))
{
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;
}
return true;
}