创建Java应用程序,该应用程序将捕获Google Drive更改并将Java客户端用于Google Drive V3 API。下面的代码显示了我们如何调用Changes.List方法来返回驱动器更改列表。
对此页面令牌3411的https://developers.google.com/drive/v3/reference/changes/list给出了列表
{
"kind": "drive#changeList",
"newStartPageToken": "3420",
"changes": [
{
"kind": "drive#change",
"type": "file",
"time": "2017-06-11T10:23:44.740Z",
"removed": false,
"fileId": "0B5nxCVMvw6oHaGNXZnlIb1I1OEE",
"file": {
"kind": "drive#file",
"id": "0B5nxCVMvw6oHaGNXZnlIb1I1OEE",
"name": "NewsLetters",
"mimeType": "application/vnd.google-apps.folder"
}
},
{
"kind": "drive#change",
"type": "file",
"time": "2017-06-11T10:23:49.982Z",
"removed": false,
"fileId": "0B5nxCVMvw6oHeWdTYzlsOWpFOEU",
"file": {
"kind": "drive#file",
"id": "0B5nxCVMvw6oHeWdTYzlsOWpFOEU",
"name": "Copy of Copy of learning11.txt",
"mimeType": "text/plain"
}
},
但是使用代码
AppIdentityCredential credential= new
AppIdentityCredential(Collections.singleton(DriveScopes.DRIVE_METADATA));
driveService = new Drive.Builder(
HTTP_TRANSPORT_REQUEST, JSON_FACTORY, credential)
.setApplicationName(APPLICATION_NAME)
.build();
String pageToken = "3411";
while (pageToken != null) {
ChangeList changes = driveService.changes().list(pageToken)
.execute();
Log.info("changes.getChanges 3411 "+changes.getChanges().size());
for (Change change : changes.getChanges()) {
// Process change
System.out.println("Change found for file: " + change.getFileId());
}
if (changes.getNewStartPageToken() != null) {
// Last page, save this token for the next polling interval
savedStartPageToken = changes.getNewStartPageToken();
}
pageToken = changes.getNextPageToken();
}
它给出了
Log.info("changes.getChanges 3411 "+changes.getChanges().size());
大小返回0 甚至我试过
driveService.changes().list("3411"). setFields("changes").execute()
相同的结果0 我正在使用AppEngine谷歌云服务器。 我想获得folderID中的更改列表。 我在做什么错误。任何指针。请帮忙。
这是因为 Google Drive API through Google App Engine
由于其安全模型,Drive SDK不支持服务帐户。 App Identity无法使用Drive API。这不是一个错误
但是使用AppIdentity,我能够读取文件夹
中的文件 result = service.files().list().setQ("'" + locdriveFolderID + "' in
parents")
.setPageSize(10)
.setFields("nextPageToken, files(id,
name,description,mimeType,modifiedTime)")
.setOrderBy("modifiedTime")
.execute();
为什么changes.getChanges()返回0,它应该返回由api> 1显示的更改列表。
请让我纠正。
答案 0 :(得分:0)
change.getChanges()的结果返回列表,如果
AuthorizationCodeFlow authFlow = initializeFlow();
Credential credential = authFlow.loadCredential(getUserId(req));
driveService = new Drive.Builder(
HTTP_TRANSPORT_REQUEST, JSON_FACTORY, credential)
.setApplicationName(APPLICATION_NAME)
.build();
ChangeList changes = mService.changes().list("3411").execute();
Log.info("changes.getChanges "+changes.getChanges().size() );
记录输出
changes.getChanges 10