调用Google API时出现无法连接错误(最常发生在Drive中) [英] Unable to connect errors when calling Google APIs (happens most frequently in Drive)

查看:0
本文介绍了调用Google API时出现无法连接错误(最常发生在Drive中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

星期五,我使用的是Google Drive API PHP客户端0.6版,我开始收到很多错误,看起来像

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

我升级到了1.0版本,但我仍然得到了以下内容: (0)HTTP错误:无法连接

无法打开流:连接超时

在各种场合。

这些错误是应该被捕获的吗?在https://developers.google.com/drive/web/handle-errors中没有提到这样的IO错误...

更新: 在Google Compute引擎上运行这一切,所以我更新了标记,以防这是GCE问题?

以下是我周五使用0.6客户端库的样例代码--其中$FILE_CONTENTS显然是我的文件的内容...此代码在周四似乎运行正常,错误并未定期发生

(此处将驱动对象传入函数):

  $file = new Google_DriveFile($drive->files->get($file_id));

      $additionalParams = array(
              'data' => $file_contents
          );
      try{
        $update_result = $drive->files->update($file_id,$file,$additionalParams);
        if($update_result){
          return "true";
        }else{
          return "Error: Could not update file, please try again";
        }
      }catch (Google_ServiceException $e) {
        return "Error: Could not create file, please try again (Google Error) " . $e->getMessage();
      } catch (Google_Exception $e) {
        return "Error: Could not create file, please try again (Google Error) " . $e->getMessage();
      }catch (Exception $e) {
        return "Error: " . $e->getMessage();
      }

和我使用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

这对我很管用...

这篇关于调用Google API时出现无法连接错误(最常发生在Drive中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆