简体   繁体   English

无法使用 PHP 代码访问 Google Cloud Datastore

[英]Can't access the Google Cloud Datastore with PHP code

  • I have installed the google cloud files with composer (terminal)我已经用composer(终端)安装了谷歌云文件
  • export GOOGLE_APPLICATION_CREDENTIALS='...'导出 GOOGLE_APPLICATION_CREDENTIALS='...'
  • Received my .json key from gcloud which is in the very same directory as my code从 gcloud 收到我的 .json 密钥,该密钥与我的代码位于同一目录中
  • Made 3 entities in my google Datastore在我的谷歌数据存储中创建了 3 个实体

All I'm trying to do:我正在尝试做的所有事情:

<?php
  session_start();
  require __DIR__ . '/vendor/autoload.php';
  use Google\Cloud\Datastore\DatastoreClient;
  putenv('GOOGLE_APPLICATION_CREDENTIALS=...');

  // Various checks
  if(isset($_POST["userId"]) && isset($_POST["password"])){
    $userId = $_POST["userId"];
    $password = $_POST["password"];
    $datastore = new DatastoreClient(["..." => $projectId]);
    $key = $datastore->key($userId, $password);
    $entity = $datastore->lookup($key);
    if($entity != null){
      // do stuff...
    }
?>

The page loads fine it's just when I submit the form it crashes giving exceptions/errors stating it can't find the .json file or it can't verify my credentials.页面加载正常,只是当我提交表单时它崩溃并给出异常/错误,说明它无法找到 .json 文件或无法验证我的凭据。

[Update]: By placing the putenv() it seems the datastore object can be made but whenever I try to retrieve an entity using the lookup() function I get the following error code: [更新]:通过放置 putenv() 似乎可以创建数据存储对象,但是每当我尝试使用 lookup() 函数检索实体时,我都会收到以下错误代码:

Fatal error: Uncaught exception 'Google\Cloud\Core\Exception\ServiceException' with message
 "No system CA bundle could be found in any of the the common system 
 locations. PHP versions earlier than 5.6 are not properly configured
 to use the system's CA bundle by default. In order to verify peer 
 certificates, you will need to supply the path on disk to a
 certificate bundle to the 'verify' request option:
 http://docs.guzzlephp.org/en/latest/clients.html#verify. 
 If you do not need a specific certificate bundle, then Mozilla provides a commonly used CA bundle which can be downloaded here (provided by the maintainer of cURL): 
 https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt. 
 Once you have a CA bundle available on disk, you can set the 'openssl.cafile' PHP ini setting to point to the path to the file, allowing you to omit the 'verify' request option. 
 See http://curl.haxx.se/docs/sslcerts.html for more information."

I am very unfamiliar with what a CA bundle is or how exactly I am suppose to use it to solve the issue here.我非常不熟悉 CA 包是什么,或者我到底应该如何使用它来解决这里的问题。

Have you tried to set the env variable before as in [1]您是否尝试过像[1] 中那样设置 env 变量

<?php
  putenv('GOOGLE_APPLICATION_CREDENTIALS=...');
  session_start();
  require __DIR__ . '/vendor/autoload.php';
  use Google\Cloud\Datastore\DatastoreClient;
  # ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM