我想知道如果你收到一个webhook,如果它是添加到谷歌驱动器的新文件,修改了文件或删除了文件,该怎么知道。
@POST
@Path("/webhook")
public void webhook(@Context HttpServletRequest request, @Context HttpServletResponse response) throws IOException {
Credential credential = initFlow().loadCredential("user");
Drive service = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build();
String pageToken = GDrive.savedPageToken;
while (pageToken != null) {
ChangeList changes = service.changes().list(pageToken).execute();
for (Change change : changes.getChanges()) {
if (!change.getFile().getMimeType().equalsIgnoreCase("application/vnd.google-apps.folder")) {
//IGNORE FOLDERS
Log.info("Removed file: "+ change.toString());
}
}
if (changes.getNewStartPageToken() != null) {
GDrive.savedPageToken = changes.getNewStartPageToken();
}
pageToken = changes.getNextPageToken();
}
response.setStatus(200);
}
我只对文件更改感兴趣,因此我忽略了application / vnd.google-apps.folder。
我如何区别于这些?