[英]How do I access Cloud Datastore from AppEngine?
I created an AppEngine project and used the sample java project as a starting point. 我创建了一个AppEngine项目,并以示例Java项目作为起点。 I want my app to be able to connect to the Cloud Datastore so I went through the getting started docs and added the following to the skeleton app: 我希望我的应用程序能够连接到Cloud Datastore,因此我阅读了入门文档并将以下内容添加到了骨架应用程序:
datastore = DatastoreFactory.get().create(DatastoreHelper.getOptionsfromEnv()
.dataset(datasetId).build());
Then I built and deployed the app ( appcfg.sh -A <project> update target/appengine-try-java-1.0
) and made a request and got the following error in the logs: 然后,我构建并部署了该应用程序( appcfg.sh -A <project> update target/appengine-try-java-1.0
),并发出了一个请求,并在日志中出现以下错误:
W 17:40:59.602 2015-05-20 200 0 B 4.12s /demo
172.26.42.164 - - [20/May/2015:14:40:59 -0700] "POST /demo HTTP/1.1" 200 0 - "Apache-HttpClient/4.2.5 (java 1.5)" "project-id.appspot.com" ms=4122 cpu_ms=4667 cpm_usd=0.000158 loading_request=1 instance=00c61b117c2949ed37017839e6c82982472c2c app_engine_release=1.9.21
W 17:40:59.394 com.google.api.services.datastore.client.DatastoreFactory makeClient: Not using any credentials
W 17:40:59.575 [s~project-id/1.384441993309831713].<stderr>: Error while doing datastore operation
W 17:40:59.575 [s~project-id/1.384441993309831713].<stderr>: DatastoreException(Login Required): beginTransaction 401
Is there something I need to set up on AppEngine to let it connect to Datastore? 我需要在AppEngine上进行设置以使其连接到数据存储区吗? It doesn't seem to be able to find any credentials in the environment. 它似乎无法在环境中找到任何凭据。
If you're running on App Engine, you can use the native Datastore API ( docs ). 如果您在App Engine上运行,则可以使用本机数据存储区API( docs )。
Using the native API you don't need to connect, it's 'just there', eg: 使用本机API,您无需连接,它就在那儿,例如:
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Entity foo = new Entity("Foo");
foo.setProperty("bar", "baz");
datastore.put(foo);
Cloud Datastore tends to refer to the version of Datastore that's packaged as a service for external applications. Cloud Datastore倾向于引用打包为外部应用程序服务的Datastore版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.