首页 > 解决方案 > 谷歌 API 给出卷曲错误

问题描述

我有一个需要访问 Google 表格的独立 PHP 程序(不是 Web 服务器的一部分),而且我不断收到臭名昭著的 curl 错误 6。我尝试向 PHP.INI 文件添加证书路径,我尝试转向它在客户端配置中关闭并且没有任何工作。任何人都可以提出其他可能解决问题的建议吗?

class GoogleFunctions
 {

    private $client;
    private $accessToken;
    private $sheetsService;
    private $driveService;

    /* 
    * Establish our connection with Google and create Drive and Sheet clients
    * */
    public function initialize() {
        /*
        * We need to get a Google_Client object first to handle auth and api calls, etc.
        */
        //$http = new GuzzleHttp\Client(['verify' => './Certificates/cacert.pem']);
        //$http = new GuzzleHttp\Client(['verify' => 'C:\Development\EDPS\EDPS\Development\.credentials\cacert.pem']);
        $http = new GuzzleHttp\Client(['verify' => false]);
        $this->client = new Google_Client();
        $this->client->setHttpClient($http);
        $this->client->setApplicationName('EDPS');
        $this->client->setScopes(Google_Service_Drive::DRIVE_FILE or Google_Service_Sheets::SPREADSHEETS);
        $this->client->setAuthConfig('sheets_api_secret.json');
        $this->client->setAccessType('offline');

        $this->refreshAccessToken();

        $accessToken = $this->client->fetchAccessTokenWithAssertion()["access_token"];
        /* ServiceRequestFactory::setInstance(new DefaultServiceRequest($accessToken)); */
        $this->client->setAccessToken($accessToken);

        /*
        * Get our two services for accessing folders and sheets.
        */
        $this->sheetsService = new \Google_Service_Sheets($this->client);
        $this->driveService = new Google_Service_Drive($this->client);
}

. . .

private function refreshAccessToken() {
    if ($this->client->isAccessTokenExpired()) {
        $this->client->refreshTokenWithAssertion();
    }
}

}

代码总是在上面的函数 refreshTokenWithAssertion 中死掉,并出现 curl 错误 60。我关注了几篇建议提供您自己的 Guzzle 客户端(如上所示)的文章,但似乎没有任何效果。真正令人抓狂的是,代码在一台 Windows PC 上运行良好,但当转移到开发笔记本电脑与客户端一起工作时,它停止工作。我正在使用 Google 2 api 客户端运行 PHP 5.6.36。请问还有什么建议吗?

标签: phpgoogle-sheets-api

解决方案


推荐阅读