2017-03-02 6 views
3

이며, 연결이 완벽하게 작동하지만 언젠가는이 오류를 얻을 :서비스는 내 프로젝트 계정에 연결하기 위해 구글의 슬라이드 API를 사용하고 현재 사용할 수 없습니다 구글 API를

Fatal error: Uncaught Google_Service_Exception: { "error": { "code": 503, "message": "The service is currently unavailable.", "errors": [ { "message": "The service is currently unavailable.", "domain": "global", "reason": "backendError" } ], "status": "UNAVAILABLE" } } in /vendor/google/apiclient/src/Google/Http/REST.php:118 Stack trace: #0 /vendor/google/apiclient/src/Google/Http/REST.php(94): Google_Http_REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #1 /vendor/google/apiclient/src/Google/Task/Runner.php(181): Google_Http_REST::doExecute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #2 /vendor/google/apiclient/src/Google/Http/REST.php(58): Google_Task_Runner->run in /vendor/google/apiclient/src/Google/Http/REST.php on line 118

이 내 getClient 기능 구글 API입니다 :

public function replaceAllShapesWithImage(array $data_images) 
{ 
    $requests =array(); 
    if(isset($data_images)){ 
     foreach ($data_images as $key => $value) { 
      $requests[] = new \Google_Service_Slides_Request(array(
       'replaceAllShapesWithImage' => array(
        'imageUrl' => $value['url'], 
        'replaceMethod' => $value['replaceMethod'], 
        'containsText' => array(
         'text' => $value['text'] 
        ) 
       ) 
      )); 
     } 
    } 
    return $requests; 
} 

,538,225 :

function getClient(string $SCOPES,string $CLIENT_SECRET_PATH,string $CREDENTIALS_PATH,string $APPLICATION_NAME) { 

    $this->client->setApplicationName($APPLICATION_NAME); 
    $this->client->setScopes($SCOPES); 
    $this->client->setAuthConfig($CLIENT_SECRET_PATH); 
    $this->client->setAccessType('offline'); 
    $this->client->setApprovalPrompt('force'); 

    $credentialsPath = $this->expandHomeDirectory($CREDENTIALS_PATH); 
    if (file_exists($credentialsPath)) { 
     $accessToken = json_decode(file_get_contents($credentialsPath), true); 
    } else { 

     $authUrl = $this->client->createAuthUrl(); 
     printf("Open the following link in your browser:\n%s\n", $authUrl); 
     print 'Enter verification code: '; 
     $authCode = trim(fgets(STDIN)); 

     $accessToken = $this->client->fetchAccessTokenWithAuthCode($authCode); 

     if(!file_exists(dirname($credentialsPath))) { 
      mkdir(dirname($credentialsPath), 0700, true); 
     } 
     file_put_contents($credentialsPath, json_encode($accessToken)); 
     printf("Credentials saved to %s\n", $credentialsPath); 
    } 
    $this->client->setAccessToken($accessToken); 

    if ($this->client->isAccessTokenExpired()) { 
     $this->client->fetchAccessTokenWithRefreshToken($this->client->getRefreshToken()); 
     file_put_contents($credentialsPath, json_encode($this->client->getAccessToken())); 
    } 
    return $this->client; 
} 

이 요청은 I 샌드입니다이 값이 있습니다

'replaceAllShapesWithImage' => array(
      0 => array(
       'text'=>'{{LOGO}}', 
       'url'=>'http://www.16cafe.com/wp-content/themes/16cafe/css/images/logo.png', 
       'replaceMethod'=>'CENTER_INSIDE' 
      ), 
      1 => array(
       'text'=>'{{PHOTO}}', 
       'url'=>'http://localhost:9880/wp-content/uploads/2017/02/pla23.jpg', 
       'replaceMethod'=>'CENTER_INSIDE' 
      ), 
     ) 
+0

어떤 줄이 오류를 던지고 있습니까? – DaImTo

+0

라인 오류를 볼 수있는 내 질문을 업데이트 –

+2

@MALKIMOHAMED 503의 원인이되는 요청의 본문을 제공 할 수 있습니까? 붙여 넣은 코드는 oauth 흐름 만 수행하고 Slides API 호출을하지 않습니다. –

답변

1

슬라이드 확실히 더 나은 오류 메시지를 제공 할 수 있습니다,하지만 난 문제가 http://localhost:9880/wp-content/uploads/2017/02/pla23.jpg 이미지 URL이 삽입하려고하는 것입니다 확신 해요. 해당 이미지로 replaceAllShapesWithImage 요청을 시도하고 503을 받았습니다.

슬라이드는 공개 인터넷을 통해 이미지를 다운로드하므로 localhost 도메인이 작동하지 않습니다. 공개적으로 액세스 할 수있는 일부 URL에서 호스팅하거나 Google Drive을 사용하여 이미지를 호스팅 할 수 있습니다.

+0

오, 그래, 그게 지금 작동한다. 고마워요 @ 모리스 코딕 –