我试图在我的播放scala服务(Play v2.5.7)中使用谷歌云数据存储,因为我google-cloud在build.sbt中添加了依赖项
Run Code Online (Sandbox Code Playgroud)"com.google.cloud" % "google-cloud" % "0.4.0",
没有依赖项,服务器启动正常.但是,添加依赖项后,播放服务器启动会出错:
[info] Loading global plugins from /<redacted>/.sbt/0.13/plugins
[info] Loading project definition from /<redacted>/dev/auth-svc/project
[info] Set current project to authsvc (in build file:/<redacted>/auth-svc/)
--- (Running the application, auto-reloading is enabled) ---
java.lang.NullPointerException
at io.netty.channel.group.DefaultChannelGroup.add(DefaultChannelGroup.java:146)
at play.core.server.NettyServer.bind(NettyServer.scala:140)
at play.core.server.NettyServer.play$core$server$NettyServer$$bindChannel(NettyServer.scala:224)
at play.core.server.NettyServer$$anonfun$1.apply(NettyServer.scala:216)
at play.core.server.NettyServer$$anonfun$1.apply(NettyServer.scala:216)
at scala.Option.map(Option.scala:146)
at play.core.server.NettyServer.<init>(NettyServer.scala:216)
at play.core.server.NettyServerProvider.createServer(NettyServer.scala:279)
at play.core.server.NettyServerProvider.createServer(NettyServer.scala:278)
at play.core.server.DevServerStart$$anonfun$mainDev$1.apply(DevServerStart.scala:235)
at play.core.server.DevServerStart$$anonfun$mainDev$1.apply(DevServerStart.scala:65)
at play.utils.Threads$.withContextClassLoader(Threads.scala:21)
at play.core.server.DevServerStart$.mainDev(DevServerStart.scala:64)
at play.core.server.DevServerStart$.mainDevHttpMode(DevServerStart.scala:54)
at play.core.server.DevServerStart.mainDevHttpMode(DevServerStart.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at …Run Code Online (Sandbox Code Playgroud) 我正在尝试从AppEngine向Google Datastore插入数据,但我收到错误消息:
java.lang.IllegalArgumentException: A project ID is required for this service but could not be determined from the builder or the environment. Please set a project ID using the builder.
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:92)
at com.google.cloud.ServiceOptions.<init>(ServiceOptions.java:324)
at com.google.cloud.datastore.DatastoreOptions.<init>(DatastoreOptions.java:85)
at com.google.cloud.datastore.DatastoreOptions.<init>(DatastoreOptions.java:32)
at com.google.cloud.datastore.DatastoreOptions$Builder.build(DatastoreOptions.java:75)
at com.google.cloud.datastore.DatastoreOptions.defaultInstance(DatastoreOptions.java:123)
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
Datastore datastore = DatastoreOptions.defaultInstance().service();
KeyFactory keyFactory = datastore.newKeyFactory().kind("keyKind");
Key key = keyFactory.newKey("keyName");
Entity entity = Entity.builder(key)
.set("name", "John Doe")
.set("age", 30)
.set("access_time", DateTime.now())
.build();
datastore.put(entity);
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个错误?
嗨,我遇到了Google Cloud的Java SDK库问题。
我需要查询Dialogflow V2 API,并且正在使用此SDK(https://github.com/GoogleCloudPlatform/google-cloud-java/tree/master)
我已按照说明进行操作,以将GOOGLE_APPLICATION_CREDENTIALS设置为环境变量。
我做了几次尝试(我使用的是Mac):
export GOOGLE_APPLICATION_CREDENTIALS=path/to/my.json
Run Code Online (Sandbox Code Playgroud)
不起作用
推杆
export GOOGLE_APPLICATION_CREDENTIALS=path/to/my.json
Run Code Online (Sandbox Code Playgroud)
在.bash_profile中
不起作用
在我的Java代码中:
System.setProperty("GOOGLE_APPLICATION_CREDENTIALS", "/path/to/my.json");
GoogleCredential credential = GoogleCredential.getApplicationDefault();
Run Code Online (Sandbox Code Playgroud)
不起作用
String jsonPath = "/path/to/my.json";
GoogleCredentials credentials = GoogleCredentials.fromStream(new FileInputStream(jsonPath));
Storage storage = StorageOptions.newBuilder().setCredentials(credentials).build().getService();
Run Code Online (Sandbox Code Playgroud)
不起作用
通过“ Maven构建>环境>新变量”将GOOGLE_APPLICATION_CREDENTIALS作为Eclipse中的环境变量,然后重新启动IDE
不起作用
总是发生相同的错误:
An error occurred during Dialogflow http request: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用GQL从数据存储区中获取一些数据.
当我SELECT * FROM Kind提出请求时,它可以正常工作,我会收到数据.
但是,当我尝试:
SELECT * FROM kind where num < 1234
Run Code Online (Sandbox Code Playgroud)
我得到一个不允许的字面错误.
我甚至尝试用引号做到这一点:
SELECT * FROM kind where num < '1234'
Run Code Online (Sandbox Code Playgroud)
但我得到了同样的错误.
有没有人遇到过这个?
这是代码:
Query<Entity> query = Query.gqlQueryBuilder(Query.ResultType.ENTITY,
"SELECT * FROM " + kind + " WHERE num < '100'"
).build();
QueryResults<Entity> results = datastore.run(query);
while (results.hasNext()) {
Entity result = results.next();
myList.add(result.getString("num"));
Run Code Online (Sandbox Code Playgroud)