2017-06-11 5 views
0

Googleドライブの変更をキャプチャするJavaアプリケーションを作成し、JavaクライアントをGoogleドライブV3 APIに使用します。以下のコードは、Changes.Listメソッドを呼び出してドライブの変更のリストを返す方法を示しています。0を返すGoogleドライブリストの変更を検出しますが、同じpagetokenの戻り値はapiの変更リスト

https://developers.google.com/drive/v3/reference/changes/listページトークン3411のためにこれを以下はリストに

{ 
    "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 私はApp EngineのGoogleクラウドサーバを使用しています。 私はfolderIDの変更のリストを取得したいと思います。 私がやっている間違い。何か指摘しています。助けてください。 Google Drive API through Google App Engine

サービスアカウントが、そのセキュリティモデルにドライブSDKによってサポートされていないため

はこれです。 アプリIDがドライブ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

AppIdentityCredentialによってserviceAccountからの変更のリストを取得する方法 – user2628716

答えて

0

changes.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

関連する問題