简体   繁体   English

如何从AppEngine访问Cloud Datastore?

[英]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.

相关问题 如何从前端代码访问包com.google.appengine.api.datastore - How to access the package com.google.appengine.api.datastore from the front end code 如何将Google App Engine数据存储区中的数据写入com.google.appengine.api.datastore.Text - How do I write data in my Google App Engine Datastore to com.google.appengine.api.datastore.Text 如何使用Java从本地开发服务器访问生产数据存储区? - How do I access production Datastore from my local development server using Java? 如何从AppEngine数据存储区中删除与查询匹配的实体? - How to delete an entity from AppEngine datastore that matching a query? 如何将二进制数据字段从Appengine数据存储区导出到其他数据库? - How to export binary data fields from appengine datastore to other databases? 如何使用Java从Appengine数据存储中获取更新的对象集合? - How to bring updated collection of objects from appengine datastore with java? 在Cloud Datastore中,如果所有仪表板都显示“确定”,我如何确定要打破的配额 - In Cloud Datastore how do I figure out what quota I am breaking if all dashboards show 'Okay" Appengine无法从数据存储区检索实体 - Appengine can't retrieve Entities from datastore 无法从本地AppEngine数据存储区删除对象 - Cannot delete Object from local AppEngine datastore 如何在AppEngine上限制appengine-mapreduce? - How do I throttle appengine-mapreduce on AppEngine?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM