Привет ребята,
Я использую API Google Zend, и мне нужно перечислить все документы определенных учетных записей. Проблема заключается в том, что при вызове метода getDocumentListFeed, если отключена учетная запись google с учетной записью службы Service Account, она выдает мне исключение (код 401). И я не хочу этого. Я бы хотел попробовать раньше, если служба работает, но я не могу найти способ предоставить мне информацию?
Docs.php
const AUTH_SERVICE_NAME = 'writely';
Мой Classe
protected function GetAllDocumetsOneCollab
( $UidToWork
, $PasswordGet
) {
try {
$service = Zend_Gdata_Docs::AUTH_SERVICE_NAME ;
$client =
Zend_Gdata_ClientLogin::getHttpClient
( $UidToWork.
"@".$this -> DomainToUsed
, $PasswordGet
, $service
) ;
} catch (Zend_Gdata_App_AuthException $e) {
throw new Exception
( "[".__LINE__."] ".__FILE__.
$this -> CrLn.
$this -> Space.$this -> Space.$this -> Space.$this -> Space.$this -> Space.
$UidToWork." // ".$PasswordGet.
$this -> CrLn.
$this -> Space.$this -> Space.$this -> Space.$this -> Space.$this -> Space.
$this -> DepileErrorCatch ($e)
) ;
return null ;
}
try {
$docs = new Zend_Gdata_Docs ($client);
} catch (Zend_Gdata_App_AuthException $e) {
throw new Exception
( "[".__LINE__."] ".__FILE__.
$this -> CrLn.
$this -> Space.$this -> Space.$this -> Space.$this -> Space.$this -> Space.
$this -> DepileErrorCatch ($e)
) ;
return null ;
}
$AllDocument = array () ;
try {
$feed = $docs -> getDocumentListFeed () ;
foreach ($feed -> entries as $entry) {
$link = $entry -> getLink () ;
$Title = $entry -> getTitle () ;
$AllDocument [count ($AllDocument)] =
array ( 'title' => utf8_decode ("".$Title)
) ;
}
} catch (Zend_Gdata_App_HttpException $e) {
throw new Exception
( "[".__LINE__."] ".__FILE__.
$this -> CrLn.
$this -> Space.$this -> Space.$this -> Space.$this -> Space.$this -> Space.
$this -> DepileErrorCatch ($e)
) ;
return null ;
}
return $AllDocument ;
}
Я бы хотел проверить раньше, если служба включена так:
$IsEnable = $docs -> ServiceEnable () ;
if ($IsEnable)
$feed = $docs -> getDocumentListFeed () ;
else
$feed = array () ;
Сообщение об исключении:
Ожидаемый код ответа 200, получил 401 Служба отключена администратором Google Apps. Ошибка 401
Я не знаю, может ли один метод или свойство API дать мне информацию?
Спасибо всем и извините за мой плохой английский :)
На данный момент я сделал это так, даже если мне не нравится это решение
$service = Zend_Gdata_Docs::AUTH_SERVICE_NAME ;
$AllDocument = array () ;
try {
$feed = $docs -> getDocumentListFeed () ;
foreach ($feed -> entries as $entry) {
$link = $entry -> getLink () ;
$Title = $entry -> getTitle () ;
$AllDocument [count ($AllDocument)] =
array ( 'title' => utf8_decode ("".$Title)
) ;
}
} catch (Zend_Gdata_App_HttpException $e) {
$Response = $e -> getResponse() ;
$MsgError = $Response -> getMessage() ;
$MsgErrorAccept = "Service <".$service."> disabled by" ;
if (!strstr($MsgError, $MsgErrorAccept)) {
throw new Exception
( "[".__LINE__."] ".__FILE__.
$this -> CrLn.
$this -> Space.$this -> Space.$this -> Space.$this -> Space.$this -> Space.
$this -> DepileErrorCatch ($e)
) ;
return null ;
}
}
return $AllDocument ;