我正在尝试使用 Oauth 2.0 连接到 Google 日历。两天前工作正常,但现在抛出异常:“引起:java.lang.NoSuchMethodError:com.google.api.client.util.Strings.isNullOrEmpty(Ljava/lang/String;)Z”。
我正在使用 google-api-java-client-1.14.1。(我的库中有“google-http-client-1.14.1-beta.jar”)。
该问题仅出现在已部署的版本中,当我在本地计算机上运行应用程序时一切正常。
代码:
public GoogleCredential conexion(String email, String scope) {
GoogleCredential credential =null;
try{
// Build service account credential.
credential = new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
.setServiceAccountScopes(scope)
.setServiceAccountPrivateKeyFromP12File(new File(file))
.setServiceAccountUser(email)
.build();
}
catch(Exception e){
e.printStackTrace();
}
return credential;
}
public int function(){
GoogleCredential sa = serviceAc.conexion("user@mail.com",CalendarScopes.CALENDAR);
Calendar service = new Calendar(new NetHttpTransport(), new JacksonFactory(), sa);// here throw the exception
.
.
.
}