Google drive api 调用Google API时无法连接错误(最常发生在驱动器中)

Google drive api 调用Google API时无法连接错误(最常发生在驱动器中),google-drive-api,google-api-php-client,google-compute-engine,Google Drive Api,Google Api Php Client,Google Compute Engine,周五,我在使用GoogleDriveAPI PHP客户端版本0.6,开始出现很多错误,看起来像 PHP致命错误:未捕获异常“Google_IOException”,消息为“HTTP错误:(0)无法连接到2607:f8b0:4001:c03::54:无法访问网络” 我已升级到1.0版本,但仍获得以下信息: (0)HTTP错误:无法连接 无法打开流:连接超时 在各种场合 这些错误应该被捕获吗?在这里没有提到像这样的IO错误 更新: 在谷歌计算引擎上运行这一切,所以我更新了标签,以防这是一个GCE问题

周五,我在使用GoogleDriveAPI PHP客户端版本0.6,开始出现很多错误,看起来像

PHP致命错误:未捕获异常“Google_IOException”,消息为“HTTP错误:(0)无法连接到2607:f8b0:4001:c03::54:无法访问网络”

我已升级到1.0版本,但仍获得以下信息: (0)HTTP错误:无法连接

无法打开流:连接超时

在各种场合

这些错误应该被捕获吗?在这里没有提到像这样的IO错误

更新: 在谷歌计算引擎上运行这一切,所以我更新了标签,以防这是一个GCE问题

这是我周五使用0.6客户端库的示例代码-其中$file\u内容显然是我文件的内容。。。似乎这段代码在周四运行得很好,错误不会定期发生

(驱动对象在此被传递到函数中):

以及我使用1.0更新的代码

    include_once 'gapi_php_client_1/src/Google/Client.php';
    include_once 'gapi_php_client_1/src/Google/Service/Drive.php';
    global $session_access_token;
    global $session_expires_on;
    global $session_refresh_token;
    global $client_id;
    global $client_secret;

    $client = new Google_Client();
    $client->setApplicationName('Google+ PHP Starter Application');
    //// Visit https://code.google.com/apis/console?api=plus to generate your
    //// client id, client secret, and to register your redirect uri.
    $client->setClientId($client_id);
    $client->setClientSecret($client_secret);
    $client->setRedirectUri('postmessage');
    $client->setAccessToken($session_access_token);
    $client->refreshToken($session_refresh_token);

    try{

      $file = $drive->files->get($file_id);
      $additionalParams = array(
              'data' => $file_contents,
                'uploadType' => 'multipart'
          );
      $update_result = $drive->files->update($file_id,$file,$additionalParams);

    }catch (Google_ServiceException $e) {
       $file_save = false;
    }catch (Google_IOException $e) {
      $file_save = false;
    } catch (Google_Exception $e) {
      $file_save = false;
    }catch (Exception $e) {
      $file_save = false;
    }

如果在幕后使用fiddler或wireshark,您也可能会遇到此错误……请转到任务管理器并杀死fiddler/wireshark


它对我起作用了……

抛出原始
IOException
的代码是什么样子的?似乎您正在尝试访问IPv6地址
2607:f8b0:4001:c03::54:
,可能在尝试访问该地址时遇到了问题。引发原始
IOException
的确切行是什么?好吧,它不在该代码中,它在PHP Api客户端库中-无法连接到2607:f8b0:4001:c00::5f:网络无法访问“在gapi_PHP_Client/src/io/Google_CurlIO.PHP:123中”这是旧版本。。。在新版本中,第118行是gapi_php_client/src/Google/IO/Stream.php。。。如果响应为false,那么它只会抛出一个错误,真的不确定。那个IPv6地址似乎属于谷歌,所以这似乎是意料之中的。您环境中的某些内容可能不支持IPv6。是的,这就是令人困惑的地方。。。我的环境是谷歌计算引擎,我不知道为什么它会随机失败。ipv6地址也是在我使用curl的时候,当我使用file\u get\u内容时,仍然会从API中得到奇怪的错误,这些内容无法使用1.0版本的API进行连接。我刚刚为云sql得到了这个,所以我想这只是一个一般的API问题或我的环境
    include_once 'gapi_php_client_1/src/Google/Client.php';
    include_once 'gapi_php_client_1/src/Google/Service/Drive.php';
    global $session_access_token;
    global $session_expires_on;
    global $session_refresh_token;
    global $client_id;
    global $client_secret;

    $client = new Google_Client();
    $client->setApplicationName('Google+ PHP Starter Application');
    //// Visit https://code.google.com/apis/console?api=plus to generate your
    //// client id, client secret, and to register your redirect uri.
    $client->setClientId($client_id);
    $client->setClientSecret($client_secret);
    $client->setRedirectUri('postmessage');
    $client->setAccessToken($session_access_token);
    $client->refreshToken($session_refresh_token);

    try{

      $file = $drive->files->get($file_id);
      $additionalParams = array(
              'data' => $file_contents,
                'uploadType' => 'multipart'
          );
      $update_result = $drive->files->update($file_id,$file,$additionalParams);

    }catch (Google_ServiceException $e) {
       $file_save = false;
    }catch (Google_IOException $e) {
      $file_save = false;
    } catch (Google_Exception $e) {
      $file_save = false;
    }catch (Exception $e) {
      $file_save = false;
    }