- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在本地主机上的 Google App Engine 上运行的应用程序中使用 Google PHP API Client v2.0。当我将我的应用程序发布到 Google App Engine 产品时,我没有收到错误,但它是间歇性的,所以很难知道我是否只是在生产中走运。
我的 Google API 客户端正在尝试将文件写入我的 Google 云端硬盘。这段代码几个月来一直运行良好,但今天早上突然停止运行。我检查了 Google API 状态,他们没有报告任何中断。当我执行任何 API 调用时,我得到这个模糊的错误响应:
Fatal error: fopen(): Invalid response from API server. in /Users/me/googleappengine/stuff-otherstuff-111111/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php on line 312
该文件确实是在 Google Drive 上创建的,因此我的 API 调用可以通过,但是返回到我的脚本的任何响应都会导致致命的崩溃。
几分钟后它又开始工作了,现在又崩溃了。我真的无法在任何地方找到错误 API 服务器的无效响应
的任何解决方案......而且它是间歇性的。它似乎与我的代码无关,但 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";
}
编辑:我的代码现在似乎一直失败,并显示 API 服务器的无效响应
消息。它只会在代码与 Google 通信的地方失败。这两个地方是在我调用 refreshToken()
时(这种情况很少发生),另一个是在我调用 create()
时。
我让我的 friend 在他的机器上使用相同的设置运行这段代码(据我们所知......相同的代码、相同的库、相同的 oauth token 等)并且它对他有效。
注意:getSetting()
函数上面的代码只是从我的数据库中提取一些字符串,我将这些字符串用于配置目的。此外,setHttpClient()
调用是必需的,因为它在运行在 PHP 5.5 上的 Google App Engine 中运行,PHP 5.5 有一个搞砸了的 CA Bundle,它需要我提供一个合适的。
什么可能导致我每次都失败,但为我的 friend 工作?
最佳答案
在回答“导致此错误的原因”之前,您首先需要回答“错误是什么”。通常,暂时性网络错误是正常的,不会迫使应用程序因 fatal error 而崩溃,即使它们经常发生(例如,在发生中断或在您的情况下,是某些本地问题)。
Guzzle 当然不会将错误视为 fatal error ,因为它 sets its default HTTP context to ignore_errors => true (并返回响应)。 google-api-php-client
不会更改 ignore_errors
的默认行为,google-api-php-client-services
也不会,也不是开发服务器,也不是 PHP SDK。文本来自 API 服务器的无效响应
没有出现在上述任何项目的源代码中的任何位置,也不是来自任何 API 的记录错误响应。
鉴于此,它表明 来自 API 服务器的无效响应
的来源在应用程序代码本身的某个地方。我的猜测是,在应用程序代码中有一种类似类型的包罗万象的异常处理 block ,就像您在上面看到的那样,它吞没了任何类型的非成功响应,并以不透明的错误消息作为 fatal error 。
我能给出的最佳答案是在您的代码中查找错误消息的来源,然后告诉它记录详细信息而不是掩盖它们,这可能会揭示潜在的问题是什么以及如何解决它。
关于php - 谷歌 PHP API : "invalid response from api server",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41151664/
我正在尝试向 iOS 应用商店提交更新。我要从 Buzztouch 应用程序转到 Sprite Kit 应用程序。我能够存档 Xcode 项目并提交它。该应用程序的状态为“上传已收到”,但大约一分钟后
我收到了这个奇怪的警告。我不确定是什么原因造成的。 .dia文件扩展名应该表示核心有向图图形文件。我没有添加,应用程序几乎没有用户界面。 最佳答案 我对这个答案并不满意,但我认为它可以帮助人们,直到找
下面用作 Uri 参数的程序集限定字符串在 XAML 中工作,但在代码中使用时会出现错误。 我尝试了各种 UriKind,结果都相同。我该如何解决这个问题? [Test] public void La
我正在开发一个 Angular 应用程序,目的是将其部署到移动设备和 Web 浏览器上。设置表单样式以显示无效输入时,我应该定位 Angular“ng-invalid”类还是 HTML5“:inval
我有一个在 Google App Engine 上运行的应用程序,它是 Android 应用程序的后端。它基本上是 Android 应用程序和在我自己的服务器上运行的 MySQL 数据库之间的桥梁。
我的代码是这样的: func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle,
I need to encrypt using Python with the A256GCM algorithm, and getting back a JWT that I need to
无法成功编译webpack并生成bundle.js文件。据我了解,我的 src_dir 和 dist_dir 变量能够指向正确的路径,但在尝试编译时我仍然始终收到两个错误之一。 配置对象无效。 Web
因此,当我在 postgres 上运行 regexp_matches 时收到一条错误消息,并且无法弄清楚如何通过它。它似乎在 regex101 等 reg_exp 测试站点上运行良好,但不幸的是在实际
这些是我正在使用的导入: import com.novell.ldap.*; import java.io.UnsupportedEncodingException; 我正在尝试进行一个非常简单的密码
在记录器函数的简写情况下,Pylint 提示 Invalid constant name "myprint"(invalid-name)。 # import from utils import get
我试图创建一个HTML输入标签,该标签仅接受以2种格式之一输入的数字,并拒绝所有其他输入。 我只想接受以下格式的数字,包括破折号: 1234-12 和 1234-12-12 注意:不是日期,而是合法的
我一直在尝试使用 Bootstrap 的表单样式处理 AngularJS 的电子邮件验证,并遇到了这个 CSS block 。 input:focus:required:invalid, textar
我正在编写一个程序,以确保我了解如何在 C 中正确实现单向链表。我目前正在哈佛的 CS50 类(class)中学习,并且使用本教程,因为 CS50 人员不解释链接详细列出数据结构:https://ww
此问题与询问同一消息的另一个问题不重复,但在另一个上下文中。这个问题的上下文只是关于上传截图图像和获取消息。 今天,我在将图片上传到 App Store Connect 时收到一条新消息: Inval
我的代码似乎运行良好,但当我滑动以删除 UITableView 中的一行时,应用程序崩溃并显示以下内容: 错误 LittleToDoApp[70390:4116002] *** Terminating
当我尝试发送语音消息时,总是收到无效的url错误。我正在使用Whisper将音频转换为文本,但由于某种原因,我似乎无法将文件传递给Whisper。当我在Java脚本中使用它而不是在TypeScrip中
我正在尝试在 flutter 上对 http 客户端进行单元测试。在模拟 http 和我的存储库类之后: void main() { MockHttpCLient mockHttpCLient;
我正在使用 pandoc 作为一个库,相关的代码片段是: module Lib ( latexDirToTex, latexToTxt ) where import qualified
我正在开发一个(相对简单的)Rails应用程序。我正在使用Devise gem处理用户 session 。每当我导航到localhost:3000/users/sign_in时,我都会看到Devise
我是一名优秀的程序员,十分优秀!