localhost의 Google App Engine에서 실행중인 앱에서 Google PHP API 클라이언트 v2.0을 사용하고 있습니다. 내 앱을 Google App Engine 프로덕션에 게시 할 때 오류가 발생하지 않았지만 간헐적으로 인해 프로덕션 환경에서 운이 좋았는지 알기가 어렵습니다.Google PHP API : "api 서버의 응답이 없습니다."
내 Google API 클라이언트가 내 Google 드라이브에 파일을 쓰려고합니다. 이 코드는 2 개월 동안 잘 작동했지만 오늘 아침에 갑자기 작동을 멈췄습니다. Google API 상태를 확인했는데 중단이보고되지 않습니다.
치명적인 오류 :하면 fopen() API 서버에서 잘못된 응답 내가 API 호출 중 하나를 실행하면,이 모호한 오류 응답을 얻을. 라인 /Users/me/googleappengine/stuff-otherstuff-111111/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php 에 312
파일은 구글에 생성됩니까 드라이브 때문에 내 API 호출이 끝났지 만 어떤 응답이 내 스크립트로 돌아 오더라도 치명적인 충돌이 발생합니다.
몇 분 동안 다시 작업하기 시작했습니다. 이제 다시 충돌합니다. 오류 Invalid response from API server
에 대한 해결책을 찾을 수 없습니다. 간헐적입니다. 그것은 내 코드와 관련이있는 것으로 보이지 않지만 Google은 어떤 종류의 중단도 발생하지 않는다고 말합니다.
무엇이 누락 되었습니까? 이 문제를 어떻게 해결할 수 있습니까?
<?php
include_once('code-base.php');
require_once('vendor/autoload.php');
$client = new Google_Client();
$client->setApplicationName(getSetting('APP_NAME'));
$client->setAuthConfig(json_decode(getSetting('localhost_google_client_secret'), true));
$client->setAccessType("offline");
$client->setScopes(array(Google_Service_Drive::DRIVE));
$client->setHttpClient(new GuzzleHttp\Client(['verify'=>'ca-bundle.crt']));
$accesstoken = json_decode(getSetting('localhost_google_oauth_token'), true);
$client->setAccessToken($accesstoken);
// Refresh the token if it's expired.
if ($client->isAccessTokenExpired()) {
print "access token is expired\n";
$refreshtoken = getSetting('localhost_google_refresh_token');
print "refresh token: $refreshtoken\n";
$client->refreshToken($refreshtoken);
$newtokenjson = json_encode($client->getAccessToken());
print "new token: $newtokenjson\n";
printf("before: %s\n\nafter: %s\n\n", $accessToken, $newtokenjson);
//file_put_contents($credentialsPath, $newtokenjson);
updateSetting('localhost_google_oauth_token', $newtokenjson);
}
print "after checking access token expired\n";
print "before drive service\n";
$driveservice = new Google_Service_Drive($client);
print "after drive service\n";
$parentfolderid = getSetting('GDRIVE_EXPORT_DUMP');
$title = "00005 test gdrive.csv";
$filetype = 'text/csv';
$contents = "The quick brown fox jumped over the lazy dog.";
$file = new Google_Service_Drive_DriveFile();
$file->setName($title);
$file->setDescription($title);
$file->setMimeType($filetype);
$file->setParents(array($parentfolderid));
try {
if ($contents == null) {
print "contents of file are null, creating empty file\n";
$createdFile = $driveservice->files->create($file);
print "after creating empty file\n";
} else {
$contentsarray = array('data' => $contents, 'mimeType' => $filetype, 'uploadType' => 'media');
if ($options != null) {
foreach($options as $key => $value) {
$contentsarray[$key] = $value;
}
}
print "file contents: ".var_export($contentsarray, true)."\n";
$createdFile = $driveservice->files->create($file, $contentsarray);
print "after create file with contents\n";
}
return $createdFile;
} catch (Exception $e) {
print "EXCEPTION: An error occurred: " . $e->getMessage()."\n";
}
편집 : 내 코드는 Invalid response from API server
메시지를 일관되게 실패한 것으로 보인다. 코드가 Google과 통신하는 지점에서만 오류가 발생합니다. 그 두 곳은 refreshToken()
(드물게 만 발생)이라고 부르는 경우이고 다른 하나는 create()
이라고 할 때입니다.
동일한 설정 (동일한 코드, 동일한 라이브러리, 동일한 oauth 토큰 등)을 사용하여 내 컴퓨터에서이 정확한 코드를 실행하도록했습니다. 그 코드가 작동합니다.
참고 : 위의 코드는 getSetting()
함수를 사용하여 구성 목적으로 사용하는 데이터베이스에서 일부 문자열을 가져옵니다. 또한 setHttpClient()
호출이 필요합니다. 이는 CA 묶음이 엉망인 PHP 5.5에서 실행되는 Google App Engine 내부에서 실행되기 때문에 호출해야하며 적절한 패키지를 제공해야합니다.
매번 나를 위해 실패 할 수도 있지만 내 친구를 위해 일할 수 있습니까?
오류의 원인이되는 코드를 게시해야합니다. – DaImTo
특정 코드는 아닙니다. 간헐적으로 발생하며 Google에 API 호출을하는 모든 코드 행에서 발생할 수 있습니다. Remote Apps Scripts 호출을 실행하는 행에서 오류가 발생하는 경우, Google 드라이브 호출을 통해 파일 목록을 가져올 때마다 또 다른 시점에 Google 드라이브 호출을 통해 파일 목록을 가져올 때 파일. 그런 다음 동일한 호출이 모두 코드를 실행하는 다음 20 번 작동합니다. –
질문에서 오류의 원인에 대한 정보가 충분하지 않습니다. [this] (https://github.com/google/google-api-php-client)가 사용중인 PHP API 클라이언트라고 가정합니다. 'StreamHandler' 코드에서'fopen' 오류를 기반으로, 나는 드라이브에서 파일을 생성하거나 읽는 중 오류가 발생했다고 의심합니다. 이 오류를 재현 할 수있는 최소한의 코드 샘플을 제공해 주시면 기꺼이 조사해 드리겠습니다. – Nicholas