Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Google驱动器权限列表rest调用不会返回所有权限_Java_Google App Engine_Google Drive Api - Fatal编程技术网

Java Google驱动器权限列表rest调用不会返回所有权限

Java Google驱动器权限列表rest调用不会返回所有权限,java,google-app-engine,google-drive-api,Java,Google App Engine,Google Drive Api,我现在陷入了一个似乎无法解决的问题。也许有人可以澄清我做错了什么,或者更好地了解正在发生的事情 我在Google Drive中有一个文件/文件夹,它(1)在域级别上仅与链接共享,(2)与某些特定用户共享。在我当前用Java编写的应用程序中,我希望获得当前在此文件/文件夹上设置的所有权限 显然,我的第一个切入点是测试权限列表调用:授予以下权限来测试rest调用: 驱力 drive.appdata drive.apps.readonly 驱动器文件 drive.readonly 我的呼叫结果包含

我现在陷入了一个似乎无法解决的问题。也许有人可以澄清我做错了什么,或者更好地了解正在发生的事情

我在Google Drive中有一个文件/文件夹,它(1)在域级别上仅与链接共享,(2)与某些特定用户共享。在我当前用Java编写的应用程序中,我希望获得当前在此文件/文件夹上设置的所有权限

显然,我的第一个切入点是测试权限列表调用:授予以下权限来测试rest调用:

  • 驱力
  • drive.appdata
  • drive.apps.readonly
  • 驱动器文件
  • drive.readonly
我的呼叫结果包含对用户和域(类型)授予的权限。以下是的回应:

200 OK
- SHOW HEADERS -
{
 "kind": "drive#permissionList",
 "etag": "\"xxxxxxxxxx\"",
 "selfLink": "https://www.googleapis.com/drive/v2/files/xxxxxxxxxx/permissions",
 "items": [
  {

   "kind": "drive#permission",
   "etag": "\"xxxxxxxxxx\"",
   "id": "xxxxxxxxxx",
   "selfLink": "xxxxxxxxxx",
   "name": "Owner Name",
   "emailAddress": "owner@random-domain.com",
   "domain": "random-domain.com",
   "role": "owner",
   "type": "user"
  },
  {

   "kind": "drive#permission",
   "etag": "\"xxxxxxxxxx\"",
   "id": "xxxxxxxxxx",
   "selfLink": "xxxxxxxxxx",
   "name": "User Name",
   "emailAddress": "user@random-domain.com",
   "domain": "random-domain.com",
   "role": "writer",
   "type": "user",
   "photoLink": "xxxxxxxxxx"
  },
  {

   "kind": "drive#permission",
   "etag": "\"xxxxxxxxxx\"",
   "id": "xxxxxxxxxx",
   "selfLink": "xxxxxxxxxx",
   "name": "Domain Name",
   "domain": "random-domain.com",
   "role": "reader",
   "type": "domain",
   "withLink": true
  }
 ]
}
到目前为止还不错。在上面的响应中,您可以看到已返回以下权限:所有者、用户、与链接共享的域。所以现在我正试图在我的项目中做同样的事情

public static void myAwesomeMethod(String fileId) {
    Drive service = DriveDirectoryServiceManager.getDriveService("owner@random-domain.com");

    PermissionList permissions = service.permissions().list(fileId).execute();
    List<Permission> permissionList = permissions.getItems();
    ...
}

到目前为止,我还没有找到结果列表不同的真正原因。

我找到了问题的根源。尝试之后,我发现如果我手动将文件ID和权限ID输入java permission get方法,它确实找到了权限

显然,在比较驱动器文件夹的创建和驱动器文件夹的更新时,在“myAwesomeMethod”中传递了另一个“fileId”值。在这种特殊情况下,我在rest调用中检查的文件夹的父文件夹除了域共享之外,具有完全相同的共享权限,因此这会导致数据混乱


我能给出的唯一提示是总是在权限本身上使用一个简单的Get()来检查它。这为我带来了好处,因为它为我指明了正确的方向。

使用java,您是否能够调用权限。是否尝试获取缺少的权限?谢谢您的输入。我找到了问题的根源。尝试之后,我发现如果我手动将文件ID和权限ID输入java permission get方法,它确实找到了权限。显然,在比较驱动器文件夹的创建和驱动器文件夹的更新时,“myAwesomeMethod”中传递了另一个“fileId”值。在这种特殊情况下,我在rest调用中检查的文件夹的父文件夹除了域共享之外,具有完全相同的共享权限,因此这会导致数据混乱。您应该将其放入答案中并接受它。这样,下一个看起来很相似的人就不需要知道你已经做了什么。
public class DriveDirectoryServiceManager {

    /** Email of the Service Account */
    private static final String SERVICE_ACCOUNT_EMAIL = "xxxxxxxxxx";
    private static final String APPLICATION_NAME = "xxxxxxxxxx";

    /** Path to the Service Account's Private Key file */
    private static final String PKCS = "/xxxxxxxxxx";

    /**
     * Build and returns a Directory service object authorized with the service
     * accounts that act on behalf of the given user.
     *
     * @return Directory service object that is ready to make requests.
     */
    public static Drive getDriveService(String user)
            throws GeneralSecurityException, IOException, URISyntaxException {
        HttpTransport httpTransport = new NetHttpTransport();
        JacksonFactory jsonFactory = new JacksonFactory();

        List<String> scope = new ArrayList<>();
        scope.add(DriveScopes.DRIVE);
        scope.add(DriveScopes.DRIVE_FILE);
        scope.add(DriveScopes.DRIVE_APPDATA);
        scope.add(DriveScopes.DRIVE_APPS_READONLY);
        scope.add(DriveScopes.DRIVE_READONLY);
        InputStream keyStream = DriveDirectoryServiceManager.class.getResourceAsStream(PKCS);
        PrivateKey key = SecurityUtils.loadPrivateKeyFromKeyStore(
                SecurityUtils.getPkcs12KeyStore(), keyStream, "notasecret", "privatekey", "notasecret");
        GoogleCredential credential = new GoogleCredential.Builder()
                .setTransport(httpTransport)
                .setJsonFactory(jsonFactory)
                .setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
                .setServiceAccountScopes(scope)
                .setServiceAccountUser(user)
                .setServiceAccountPrivateKey(key)
                .build();

        return new Drive.Builder(httpTransport, jsonFactory, null).setHttpRequestInitializer(credential).setApplicationName(APPLICATION_NAME).build();
    }
}
permissionList = {ArrayList@6468}  size = 2
    0 = {Permission@6472}  size = 9
        0 = {DataMap$Entry@6481} "domain" -> "random-domain.com"
        1 = {DataMap$Entry@6482} "emailAddress" -> "owner@random-domain.com"
        2 = {DataMap$Entry@6483} "etag" -> ""xxxxxxxxxx""
        3 = {DataMap$Entry@6484} "id" -> "xxxxxxxxxx"
        4 = {DataMap$Entry@6485} "kind" -> "drive#permission"
        5 = {DataMap$Entry@6486} "name" -> "Owner Name"
        6 = {DataMap$Entry@6487} "role" -> "owner"
        7 = {DataMap$Entry@6488} "selfLink" -> "xxxxxxxxxx"
        8 = {DataMap$Entry@6489} "type" -> "user"
    1 = {Permission@6473}  size = 10
        0 = {DataMap$Entry@6556} "domain" -> "random-domain.com"
        1 = {DataMap$Entry@6557} "emailAddress" -> "user@random-domain.com"
        2 = {DataMap$Entry@6558} "etag" -> ""xxxxxxxxxx""
        3 = {DataMap$Entry@6559} "id" -> "xxxxxxxxxx"
        4 = {DataMap$Entry@6560} "kind" -> "drive#permission"
        5 = {DataMap$Entry@6561} "name" -> "User Name"
        6 = {DataMap$Entry@6562} "photoLink" -> "xxxxxxxxxx"
        7 = {DataMap$Entry@6563} "role" -> "writer"
        8 = {DataMap$Entry@6564} "selfLink" -> "xxxxxxxxxx"
        9 = {DataMap$Entry@6565} "type" -> "user"