问题创建Google代码管理器服务对象

时间:2016-10-05 10:25:34

标签: java google-app-engine google-tag-manager

我正在使用Google跟踪代码管理器API来创建代码管理器服务对象,但我收到的错误是“ java.lang.NoClassDefFoundError:java.nio.file.Files是受限制的类。请参阅Google App Engine开发人员指南了解更多详情“。

private static final String CLIENT_SECRET_JSON_RESOURCE  = "client_secrets.json";

private static final File DATA_STORE_DIR = new File("PATH_TO_DIRECTORY");

private static final String APPLICATION_NAME = "walnutdemoapp";
private static final JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance();
private static NetHttpTransport httpTransport;
private static FileDataStoreFactory dataStoreFactory;

public static TagManager getTagManager() {
try {
  httpTransport = GoogleNetHttpTransport.newTrustedTransport();
  dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);

  // Authorization flow.
  Credential credential = authorize();
  TagManager manager = new TagManager.Builder(httpTransport, JSON_FACTORY, credential)
      .setApplicationName(APPLICATION_NAME).build();
  return manager;
} catch (Exception e) {
  e.printStackTrace(System.err);
  return null;
}
}

private static Credential authorize() throws Exception {
// Load client secrets.
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
    new InputStreamReader(TagManagerUtil.class.getResourceAsStream(CLIENT_SECRET_JSON_RESOURCE)));

// Set up authorization code flow for all auth scopes.
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport,
    JSON_FACTORY, clientSecrets, TagManagerScopes.all()).setDataStoreFactory(dataStoreFactory)
    .build();

// Authorize.
return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
}

我在创建新的FileDataStoreFactory时遇到了异常,我无法弄明白为什么。我需要设置用户的凭证以及采用何种格式?任何类型的帮助都将受到高度赞赏.tracktrace就在这里。

java.lang.NoClassDefFoundError: java.nio.file.Files is a restricted class. Please see the Google App Engine developer's guide for more details.
at com.google.appengine.runtime.Request.process-2b983165ceac1ba1(Request.java)
at java.nio.file.Files.<clinit>(Files.java)
at java.lang.reflect.Method.invoke(Method.java:44)
at com.google.api.client.util.IOUtils.isSymbolicLink(IOUtils.java:203)
at com.google.api.client.util.store.FileDataStoreFactory.<init>(FileDataStoreFactory.java:59)
at com.adwalnut.api.TagManagerUtil.getTagManager(TagManagerUtil.java:40)
at com.adwalnut.api.CreateContainer.doGet(CreateContainer.java:42)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:446)
at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:453)
at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:276)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:312)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:304)
at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:450)
at java.lang.Thread.run(Thread.java:745)

1 个答案:

答案 0 :(得分:0)

由于分布式文件系统,在app引擎上使用文件API受到限制。您应该可以使用AppEngineDataStoreFactory代替。