我尝试从我的应用程序中获取Google云端硬盘文件列表(简单的Google帐户)(https://developers.google.com/identity/protocols/OAuth2ServiceAccount)
OAuth2授权列表完美无缺:https://developers.google.com/drive/v3/reference/files/list#try-it
我已创建服务帐户并委托Google Apps域(https://console.developers.google.com/iam-admin/serviceaccounts):
并下载json服务密钥。
从应用程序申请GD:
private static HttpTransport HTTP_TRANSPORT;
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
static {
try {
HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
} catch (Throwable t) {
t.printStackTrace();
System.exit(1);
}
}
public static void main(String[] args) throws IOException {
Credential credential = GoogleCredential
.fromStream(new FileInputStream(".\\config\\google_drive_api.json"))
.createScoped(DriveScopes.all());
Drive service = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setApplicationName("javawebinar-1314").build();
FileList result = service.files().list().execute();
List<File> files = result.getFiles();
System.out.println(files.size());
API工作:开头的结果是单一的&#34;入门&#34;文件,现在结果是0.似乎服务帐户与我自己没有任何关系,并且委托给doman对我没有任何影响,因为我没有域帐户。
是否有可能通过REST API管理我的简单谷歌帐户谷歌驱动器文件?