Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Google应用程序默认凭据在云中不工作_Java_Google App Engine - Fatal编程技术网

Java Google应用程序默认凭据在云中不工作

Java Google应用程序默认凭据在云中不工作,java,google-app-engine,Java,Google App Engine,我正在尝试在Java Google应用程序引擎应用程序中使用应用程序默认凭据。在本地运行时,凭据工作正常,下面的示例代码按预期记录我的服务帐户ID和访问令牌 import com.google.api.client.googleapis.auth.oauth2.GoogleCredential; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletE

我正在尝试在Java Google应用程序引擎应用程序中使用应用程序默认凭据。在本地运行时,凭据工作正常,下面的示例代码按预期记录我的服务帐户ID和访问令牌

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;

protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

  //Literally one line of code for GAE credentials
  GoogleCredential credential = GoogleCredential.getApplicationDefault();

  LOGGER.log(Level.INFO, "Service Account Id: {0}", credential.getServiceAccountId());
  LOGGER.log(Level.INFO, "Access Token: {0}", credential.getAccessToken()); 
}
但是,当运行部署在云中的这段代码时,日志如下所示:

16:03:58.585 com.test.servlet.MyServlet doGet: Service Account Id: null
16:03:58.681 com.test.servlet.MyServlet doGet: Access Token: null
在云中应用程序默认凭据为空有什么原因吗?我是否缺少一些配置?根据建议,这应该只是自动工作:

如果需要在Google App Engine上运行代码,则应使用应用程序默认凭据(ADC)。使用ADC的客户端库在运行时自动从App Engine获取内置服务帐户凭据


我也看到了这一点。你能找到这个吗?我从来没能解决这个问题。最后,我只是将AuthCredentials.createForJson()与我的服务帐户密钥文件一起使用。也存在此问题,但您当前无法从默认appengine凭据获取该信息。如果必须模拟某人,则必须在资源中添加.json并手动解析。