public function getSharedEmbedLink(array $fileData) { $accessToken = $this->getAccessToken(); $fileId = $fileData['id']; $http = new CHTTP(); $http->http_timeout = 10; if (!$http->GET("https://apis.live.net/v5.0/{$fileId}/embed?access_token=" . urlencode($accessToken))) { return false; } // error checking if ($http->status != "200") { return false; } $response = json_decode($http->result, true); if (preg_match('%src="(.*)"%iuU', $response['embed_html'], $m)) { return $m[1]; } return false; }
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; }