对于Mirror.Accounts.Insert类型,方法execute()未定义

时间:2014-09-07 06:45:45

标签: google-glass google-mirror-api

我正在使用Java和Eclipse IDE为Google Glass Mirror API创建服务器端动态Web项目。在我的Web项目中,我在WEB-INF下有一个lib文件夹

在lib文件夹中,我添加了以下.jar文件

  • 谷歌-API的客户端 - 1.18.0-RC-sources.jar

  • 谷歌-API服务镜-V1-rev66-1.19.0.jar

  • 谷歌的集合-1.0-rc2.jar

  • 谷歌-HTTP-客户1.18.0-rc.jar

  • 谷歌-HTTP-客户杰克逊1.19.0.jar

我的服务器端代码是

 @SuppressWarnings("serial")
    public class GlassAuthenticateUser extends HttpServlet{

public static Mirror getMirrorService() throws GeneralSecurityException,
IOException, URISyntaxException {
    HttpTransport httpTransport = new NetHttpTransport();
    JacksonFactory jsonFactory = new JacksonFactory();

    GoogleCredential credential = new GoogleCredential.Builder()
    .setTransport(httpTransport)
    .setJsonFactory(jsonFactory)
    .setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
    .setServiceAccountScopes(MIRROR_ACCOUNT_SCOPES)
    .setServiceAccountPrivateKeyFromP12File(
            new java.io.File(SERVICE_ACCOUNT_PKCS12_FILE_PATH))
            .build();
    Mirror service = new Mirror.Builder(httpTransport, jsonFactory, null)
    .setHttpRequestInitializer(credential).build();
    return service;
}

public static void createAccount(Mirror mirror, String userToken, String accountName,
        String authTokenType, String authToken) {
    try {
        Account account = new Account();
        List<AuthToken> authTokens = Lists.newArrayList(
                new AuthToken().setType(authTokenType).setAuthToken(authToken));
        account.setAuthTokens(authTokens);
        mirror.accounts().insert(
                userToken, ACCOUNT_TYPE, accountName, account).execute();
    } catch (IOException e) {
        e.printStackTrace();
    }
}


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

     //TO DO             
     }
}

}

我收到以下错误

  

对于Mirror.Accounts.Insert

类型,方法execute()未定义

为什么会这样?我已下载最新的Google API Java客户端并在我的项目中使用它们。但是,它无法解析GoogleCredential

有人可以建议我应该添加哪些.jar文件来解决此问题吗?

1 个答案:

答案 0 :(得分:3)

当你需要类jar时,看起来你有google-api-client-1.18.0-rc的源jar。您应该可以从https://code.google.com/p/google-api-java-client/wiki/Downloads?tm=2下载最新的捆绑包,然后从下载的zip文件中解压缩google-api-java-client/libs/google-api-client-1.18.0-rc.jar