php - 在没有作曲家的情况下使用 Google 电子表格 API:如何使其工作?
问题描述
我在我的 FTP 服务器上使用 Google 电子表格 API 时遇到了 3 天的问题。OVH serv 不允许安装 Composer,所以我试图在没有这个工具的情况下安装它。我尝试了几件事,但到目前为止,它们都不能正常工作:
- 安装v1-master分支
- 使用我的/vendor/autoload.php将它添加到我的供应商文件夹中,如下所示:
function google_api_php_client_autoload($className){
$classPath = explode('_', $className);
if ($classPath[0] != 'Google') {
return;
}
// Drop 'Google', and maximum class file path depth in this project is 3.
$classPath = array_slice($classPath, 1, 2);
$filePath = dirname(__FILE__) . '/' . implode('/', $classPath) . '.php';
if (file_exists($filePath)) {
require_once($filePath);
}
}
spl_autoload_register('google_api_php_client_autoload');
?>
- 并尝试在我的 script.php 中调用 Google API,如下所示:
<?php
define('DOCROOT', dirname(__FILE__));
use Spreadsheet\DefaultServiceRequest;
use Spreadsheet\ServiceRequestFactory;
if(!function_exists('classAutoLoader')){
function classAutoLoader($class_name) {
$class_name = str_replace('\\','/',$class_name);
require_once(DOCROOT."/src/".$class_name.".php");
}
}
spl_autoload_register('classAutoLoader');
- 或者也像这样:
require __DIR__ . '/vendor/autoload.php';
- 我正在尝试使用Google 电子表格 API进行这些 API 调用
$client = new Google_Client();
$client->setApplicationName('Google Sheets API PHP');
$client->setScopes(Google_Service_Sheets::SPREADSHEETS);
$client->setAuthConfig('credentials.json');
$client->setAccessType('offline');
$service = new Google_Service_Sheets($client);
$spreadsheetId = "1LLpSUVBAA3dSiyOG4lKDHDxqeldazzdads";
- 我还在我的 ROOT 文件夹中添加了与 Composer 一起使用的json 文件(composer.json、composer.lock 和 credentials.json)(在本地,它运行良好)。
- 除此之外,我还试图让它与其他谷歌库一起工作,比如googleapis-master和google-api-php-client-2.8.1
文件 token.json 的内容:
{
"type": "service_account",
"project_id": "ambient-airlock-*****",
"private_key_id": "*****************",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIE*****************==\n-----END PRIVATE KEY-----\n",
"client_email": "*****************@ambient-airlock-*****************.iam.gserviceaccount.com",
"client_id": "*****************",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/*****************%40ambient-airlock-***********.iam.gserviceaccount.com"
}
我确信我在使用这些的方式上遗漏了一些东西,但如果有人能向我解释如何在没有 Composer 的情况下使其正常工作,我将不胜感激。
解决方案
推荐阅读
- javascript - 如何使用 redux 中的对象数组更新多个对象属性?
- reactjs - 无法从更新 React.js 状态
- symfony - 在 Symfony 中拥有一个与实体没有关联的自定义存储库
- c# - 无法将 Redis.RedisValue 转换为 Task
- html - Angular 6中包含冒号的事件名称的事件绑定
- python - 如何将 gtk 小部件绑定到 python 变量或@property?
- r - 根据数据类型为 R 中的行分配上一个值
- java - 为什么持续调用 onGeolocationPermissionsShowPrompt?
- r - R闪亮的导入传单html小部件对象
- alibaba-cloud-ecs - E-MapReduce 集群中的 ZooKeeper 服务