【发布时间】:2017-07-21 09:08:57
【问题描述】:
我已经阅读了谷歌云存储(GCS)的文档,我很困惑。
让我描述一下情况:
之前 我正在使用一个简单的 php 脚本从 SQL 表中备份数据。每隔一小时。之后我将它发送到我的 ftp 服务器。 现在 现在我想被送到谷歌近线冷库。
在脚本很简单之前,没有什么花哨的只是一点 PHP
passthru('curl --connect-timeout 30 --max-time 3600 -T '.$file_path.' "ftp://'.$ftp_server['user'].':'.$ftp_server['pass'].'@'.$ftp_server['ip'].':'.$ftp_server['port'].$ftp_server['path'].'/'.$filename.'.gz"', $status_result);
现在我阅读了谷歌云 API,我很困惑实际上如何更改我的 PHP 脚本,以便它将 gz 文件发送到近线冷存储。
我读到这个:https://developers.google.com/api-client-library/php/
我有以下问题
-
它说我必须包含 google API,我该怎么做?在示例中,它说我应该使用命令“$ composer require google/cloud”,然后在我的 PHP 文件中写入:“use Google\Cloud\ServiceBuilder;”但我没有在服务器上使用作曲家。服务器是用纯 PHP 编写的。
- 如果我有一个简单的 php 文件(例如history_dump.php),如何将谷歌云 API 作为外部链接包含在内?
- 我现在做的方式是 SQL -> csv -> gz,我不想改变我可以将 gz 文件发送到 GCS 吗?怎么样?
提前谢谢你
【问题讨论】:
-
我现在也写了一个 php 脚本,但它给了我这样的错误: HTTP/1.1 401 Unauthorized X-GUploader-UploadID: ********_7hxso Vary: Origin Vary: X-Origin WWW-Authenticate: Bearer realm="accounts.google.com", error=invalid_token Content-Type: application/json; charset=UTF-8 内容长度:249 日期:格林威治标准时间 2017 年 7 月 21 日星期五 14:50:50 服务器:UploadServer { "error": { "errors": [ { "domain": "global", "reason": "authError", "message": "Invalid Credentials", "locationType": "header", "location": "Authorization" } ], "code": 401, "message": "Invalid Credentials" } }
-
HTTP 401 Unauthorized响应表明您没有通过正确的凭据进行身份验证。您可以阅读Authentication和Application Default Credentials以了解如何配置凭据并将 API 调用传递到 Cloud Storage。
标签: php google-cloud-storage google-compute-engine