/** * * @param CloudFile $cloudfile * @param type $path * @return type */ public function store($cloudfile, $path) { if (!$this->isAuthorized()) return CloudDriveResponse::AUTHORIZATION_ERROR; return $this->downloadToFile($this->url() . "/" . $cloudfile->id(), $path, null, $this->username() . ":" . $this->password()); }
/** * * @param CloudFile $cloudfile * @param type $path * @return type */ public function store($cloudfile, $path) { if (!$this->isAuthorized()) return CloudDriveResponse::AUTHORIZATION_ERROR; $key = file_get_contents(realpath(dirname(__FILE__)) . "/googledrive_key.p12"); if (!$key) return CloudDriveResponse::AUTHORIZATION_ERROR; $email = $this->getExtApp()->getParam(GoogleDriveApp::EMAIL)->value(); $cred = new Google_Auth_AssertionCredentials($email, array(Google_Service_Drive::DRIVE), $key); $this->client->setAssertionCredentials($cred); $cred->sub = $email; $request = new Google_Http_Request($cloudfile->id(), 'GET', null, null); $httpRequest = $this->client->getAuth()->authenticatedRequest($request); if ($httpRequest->getResponseHttpCode() == 200) { try { $fout = fopen($path, "w+b"); file_put_contents($path, $httpRequest->getResponseBody()); fclose($fout); return CloudDriveResponse::OK; } catch (Exception $ex) { return CloudDriveResponse::FILE_NOT_SAVED; } } else { return CloudDriveResponse::FILE_NOT_FOUND; } }