使用Google Drive API v2 rev 75我正在尝试将文件插入AppData文件夹,但插入失败时显示:
com.google.api.client.googleapis.json.GoogleJsonResponseException:403
“当前范围不允许使用appdata文件夹”
范围“https://www.googleapis.com/auth/drive.appdata”虽然在API控制台中指定,但我有点卡住了。
插入代码为:
File file = new File();
file.setTitle("myfile");
file.setDescription("configuration file");
file.setMimeType("text/plain");
file.setParents(Arrays.asList(new ParentReference().setId("appdata")));
try {
File file1 = service.files().insert(file, ByteArrayContent.fromString("text/plain", "some settings")).execute();
} catch (IOException e) {
log.severe("An error occured: " + e);
return null;
}
我使用的授权代码遵循DrEdit [样本]中详述的内容( https://code.google.com/p/google-drive-sdk-samples/source/browse/java/src/com/google/drive/samples/dredit/CredentialMediator.java?r=54312a4a583d5a2ba546330a892c4b0aca75c00d)
我的代码的特定代码段包括:
public static final List<String> SCOPES = Arrays.asList(
// Required to access and manipulate files.
"https://www.googleapis.com/auth/drive.file",
...
"https://www.googleapis.com/auth/drive.appdata");
...
CredentialMediator mediator = new CredentialMediator(req, authSecrets.getClientSecretsStream(), SCOPES);
...
GoogleAuthorizationCodeRequestUrl urlBuilder =
new GoogleAuthorizationCodeRequestUrl(
secrets.getWeb().getClientId(),
secrets.getWeb().getRedirectUris().get(0),
scopes)
.setAccessType("offline")
.setApprovalPrompt("force");
为什么我会遇到这个问题的任何想法?感谢。