我从谷歌获取了以下代码 documentation .
public static void detectDriveChanges() throws IOException {
StartPageToken response = DRIVE.changes()
.getStartPageToken().execute();
String savedStartPageToken = response.getStartPageToken();
System.out.println("Start token: " + savedStartPageToken);
// Begin with our last saved start token for this user or the
// current token from getStartPageToken()
String pageToken = savedStartPageToken;
while (pageToken != null) {
ChangeList changes = DRIVE.changes().list(pageToken)
.setFields("*")
.execute();
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();
}
}
.setFields("*") 导致以下错误请求响应。
Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Bad Request",
"reason" : "badRequest"
} ],
"message" : "Bad Request"
如果我将 setfields 中的 * 更改为文本,则会得到无效参数。如果我完全删除它,就不会出现任何错误。我在谷歌上搜索试图确定在这种情况下 setFields 可能的参数是什么,但我没有找到任何东西。
在此实例中,我在哪里可以找到 setFields 的可能参数列表?
为什么当setFields设置为*时上面的代码会失败
我正在使用以下依赖项
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-drive</artifactId>
<version>v3-rev40-1.22.0</version>
</dependency>
问候 康特
最佳答案
Drive API 的 setField
用于部分响应,这取决于您想要将哪些数据作为返回对象的一部分。
在其上设置“*”将不起作用,因为它不代表Response
中的任何字段。目的。要使其正常工作,您要么不设置字段来获取所有值,要么指定仅必需的字段(取决于您调用的 API,对于changeList,它可以是 changes
、nextPageToken
、newStartPageToken
、kind
关于java - Google Drive API 中 setFields 的有效值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39368417/