简体   繁体   English

尝试使用GDS访问Google Cloud Datastore

[英]Trying to use GDS to access Google Cloud Datastore

I'm using Tom Walder's GDS PHP Library to access Google Datastore. 我正在使用Tom Walder的GDS PHP库访问Google数据存储。

https://github.com/tomwalder/php-gds https://github.com/tomwalder/php-gds

This is my latest attempt: 这是我最近的尝试:

require_once 'src/GDS/Entity.php';
require_once 'src/GDS/Gateway.php';
require_once 'src/GDS/Mapper.php';
require_once 'src/GDS/Schema.php';
require_once 'src/GDS/Store.php';
require_once 'src/GDS/Exception/Contention.php';
require_once 'src/GDS/Exception/GQL.php';
require_once 'src/GDS/Gateway/GoogleAPIClient.php';
require_once 'src/GDS/Gateway/ProtoBuf.php';
require_once 'src/GDS/Mapper/GoogleAPIClient.php';
require_once 'src/GDS/Mapper/ProtoBuf.php';
require_once 'src/GDS/Mapper/ProtoBufGQLParser.php';
require_once 'src/GDS/Property/Geopoint.php';

// Build a new entity
$obj_book = new GDS\Entity();
$obj_book->title = 'Romeo and Juliet';
$obj_book->author = 'William Shakespeare';
$obj_book->isbn = '1840224339';

// Write it to Datastore
$obj_store = new GDS\Store('Book');
$obj_store->upsert($obj_book);

$obj_store = new GDS\Store('Book');
foreach($obj_store->fetchAll() as $obj_book) {
    echo "Title: {$obj_book->title}, ISBN: {$obj_book->isbn} <br />", PHP_EOL;
}

Which is producing this error: 产生此错误:

Fatal error: Uncaught exception 'Exception' with message 'Could not determine DATASET, please pass to GDS\Gateway\ProtoBuf::__construct()' in /var/www/html/src/GDS/Gateway/ProtoBuf.php:70 Stack trace: #0 /var/www/html/src/GDS/Store.php(81): GDS\Gateway\ProtoBuf->__construct() #1 /var/www/html/test.php(32): GDS\Store->__construct('Book') #2 {main} thrown in /var/www/html/src/GDS/Gateway/ProtoBuf.php on line 70

I'm trying really hard to get this to work. 我非常努力地使它工作。 If any of you could help me I'd really appreciate it! 如果有谁可以帮助我,我将不胜感激!

It looks like you are trying to run this script from the command line? 您似乎正在尝试从命令行运行此脚本?

If you run it from a GAE "web" environment (like the local web server or live AppEngine) then the DATASET will be defined by the environment. 如果您是从GAE“ Web”环境(例如本地Web服务器或实时AppEngine)运行的,则DATASET将由该环境定义。

Can you confirm exactly how you are trying to use the library? 您能否确切确认您尝试使用该库的方式? Then I can give you pointers. 然后我可以给你指点。

For now - try running your code in response to a web request (ie from http://localhost:8080/test.php - or whatever) 现在-尝试运行您的代码以响应Web请求(即从http:// localhost:8080 / test.php-或其他方式)

Yes, I am the author of the library. 是的,我是图书馆的作者。

If you are running on compute engine, you need to use the "JSON" Google Gateway. 如果您在计算引擎上运行,则需要使用“ JSON” Google Gateway。

There should be some samples on GitHub. GitHub上应该有一些示例。

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

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