My application is using an OAuth2 service account to copy a file from a user's Google Drive. I'm using the Google Drive client api via Java to obtain a Drive object with the requested scope being "https://www.googleapis.com/auth/drive". I'm able to make a copy of the Google Docs document, but the thumbnailLink is not retrievable. I'm getting a 403 Forbidden error. I'm quite confident this is a bug on the Google side. If I put a breakpoint in my code on he line that gets the 403 Forbidden result, I can (when logged in as the user whose Google Drive I'm copying from) use the thumbnailLink to get the thumbnail in my browser.
Here's a rewritten snippet of the code I'm using, where sourceFile is the com.google.api.services.drive.model.File that is being copied from and sourceDrive is the com.google.api.services.drive.Drive object that I mentioned above:
File newFile = new File();
newFile.setTitle( sourceFile.getTitle() );
newFile.setDescription( sourceFile.getDescription() );
newFile.setParents( sourceFile.getParents() );
File copiedFile = sourceDrive.files().copy( sourceFile.getId(), newFile ).execute();
String thumbnailLink = copiedFile.getThumbnailLink();
HttpRequest request = sourceDrive.getRequestFactory().buildGetRequest( new GenericUrl( thumbnailLink ) );
HttpResponse response = request.execute();
As mentioned above, the request.execute() line produces an exception due to the 403 Forbidden error being returned. If I put a breakpoint on the last line of the code snippet above, I am able to take the thumbnailLink and paste it into my browser that is logged in as the user whose Drive is being copied from and it gets the thumbnail returned successfully.