小编Chr*_*kin的帖子

在Google AppEngine中读取Java资源文件

我有一个Google AppEngine Java项目设置,调用BigQuery来显示查询作业的结果.我在这里可以找到我使用的示例代码和说明.该应用程序从我的开发计算机运行并检索查询,但是当我上传到AppEngine以在appspot.com上进行测试时,出现client_secrets.json文件(由于JavaScript URL授权,dev和appspot.com的不同文件)无法使用以下代码段:

  static GoogleClientSecrets getClientCredential() throws IOException {
if (clientSecrets == null) {

    clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
            new InputStreamReader(new FileInputStream(
                new File("WEB-INF/client_secrets.json"))));

  Preconditions.checkArgument(!clientSecrets.getDetails().getClientId().startsWith("Enter ")
      && !clientSecrets.getDetails().getClientSecret().startsWith("Enter "),
      "Enter Client ID and Secret from https://code.google.com/apis/console/?api=bigquery "
      + "into bigquery-appengine-sample/src/main/resources/client_secrets.json");
}
return clientSecrets;
Run Code Online (Sandbox Code Playgroud)

}

这是我的appengine-web.xml资源文件定义:

  <resource-files>
    <include path="**" />
  </resource-files>
Run Code Online (Sandbox Code Playgroud)

client_secrets.json文件在我的war文件中正确打包.我得到的错误是:

> /
Uncaught exception from servlet
java.io.FileNotFoundException: /base/data/home/apps/s~tactile-reason-849/1.385872137632330782/WEB-INF/client_secrets.json (No such file or directory)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:171)
    at com.google.api.client.sample.bigquery.appengine.dashboard.ServiceUtils.getClientCredential(ServiceUtils.java:71)
    at com.google.api.client.sample.bigquery.appengine.dashboard.ServiceUtils.newFlow(ServiceUtils.java:103)
    at com.google.api.client.sample.bigquery.appengine.dashboard.MainServlet.initializeFlow(MainServlet.java:125)
    at com.google.api.client.extensions.servlet.auth.oauth2.AbstractAuthorizationCodeServlet.service(AbstractAuthorizationCodeServlet.java:124)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) …
Run Code Online (Sandbox Code Playgroud)

java google-app-engine google-bigquery

10
推荐指数
1
解决办法
3882
查看次数

标签 统计

google-app-engine ×1

google-bigquery ×1

java ×1