php - 谷歌 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。请问还有什么建议吗?
解决方案
推荐阅读
- javascript - 如何使用 Css 提取 HTML 表的值?
- mingw-w64 - 如何使用 Mingw64 安装 Cunit
- google-api - 谷歌日历无法更新事件
- node.js - Debian,节点安装,发布文件错误
- python - 如何将大型镶木地板文件读取为多个数据帧?
- javascript - 如何在 JS 中从 DynamoDB 持续访问和更新项目?
- json - 在显示所有数据的 ionic 中遍历 JSON 数组
- go - protoc 在 go 源文件上生成导入路径
- java - 缺少使用 org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder 的方法
- javascript - 将 HTML 附加到组件和 React 组件类意外令牌,预期 }