Google Drive API v3在java中获取根文件夹Id [英] Google Drive API v3 getting root folder Id in java

查看:439
本文介绍了Google Drive API v3在java中获取根文件夹Id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我尝试了几种方法:无法在Java Api v3中获取根文件夹ID。

  String id = service.files()。get(fileId = root)。setFields(id)。execute()。getId(); 

String id = service.files()。get(fileId = root)。setFields(?fields = id)。execute()。getId();

String id = service.files()。get(root)。setFields(?fields = id)。execute()。getId();

String id = service.files()。get(fileId = root and?fields = id)。execute()。getId();

我得到这个错误:

 com.google.api.client.googleapis.json.GoogleJsonResponseException:400错误请求
{
code:400,
errors:[ {
domain:global,
location:fields,
locationType:parameter,
message:无效的字段选择? fields = id,
reason:invalidParameter
}],
message:Invalid field selection?fields = id
}

发生错误:com.google.api.client.googleapis.json.GoogleJsonResponseException:404未找到
{
code:404,
errors:[{
domain:global,
location:fileId,
locationType:参数,
消息:文件未找到:。 ,
reason:notFound
}],
message:找不到文件:。
}

我看了迁移文档和其他文章,但仍然无法获取root ID。

解决方案

请尝试以下组合,看看是否有效。

  String id = service.files()。get(root)。setFields(id)。execute()。getId(); 


I tried several things bu couldn't get the root folder id in Java Api v3.

What I tried:

String id = service.files().get("fileId=root").setFields("id").execute().getId();

String id = service.files().get("fileId=root").setFields("?fields=id").execute().getId();

String id = service.files().get("root").setFields("?fields=id").execute().getId();

String id = service.files().get("fileId=root and ?fields=id").execute().getId();

I am getting this errors:

    com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
  "code" : 400,
  "errors" : [ {
    "domain" : "global",
    "location" : "fields",
    "locationType" : "parameter",
    "message" : "Invalid field selection ?fields=id",
    "reason" : "invalidParameter"
  } ],
  "message" : "Invalid field selection ?fields=id"
}

An error occurred: com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found
{
  "code" : 404,
  "errors" : [ {
    "domain" : "global",
    "location" : "fileId",
    "locationType" : "parameter",
    "message" : "File not found: .",
    "reason" : "notFound"
  } ],
  "message" : "File not found: ."
}

I looked the migration document and other posts but still couldn't get the root id. Thanks!

解决方案

Try the following combination to see if that works.

String id = service.files().get("root").setFields("id").execute().getId();

这篇关于Google Drive API v3在java中获取根文件夹Id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆