【问题标题】:How to share a document using google-api-java-client on Android?如何在 Android 上使用 google-api-java-client 共享文档?
【发布时间】:2012-05-28 15:56:21
【问题描述】:

我想为 Google Documents List API 创建一个 Android 客户端应用程序,考虑到它可能会在不久的将来被 Google Drive API 取代。因此,我使用 google-api-java-client 实现了身份验证,这可能会在需要时轻松过渡到新 API。

现在我正在尝试扩展在 Google 提供的 shared-sample-docs 项目中找到的 DocsClient.java 类,以便能够与用户联系人共享文档。

我没有找到比@yanivinbar 写的以下介绍更好的信息:http://javadoc.google-api-java-client.googlecode.com/hg/1.4.1-beta/com/google/api/client/googleapis/xml/atom/package-summary.html

从 Google Documents List API 文档中,我发现 ACL 用于让其他用户访问特定文档。但是,我不清楚应该实施哪些方法来实现此或其他常见的 API 相关事务。

【问题讨论】:

    标签: android google-docs google-docs-api google-api-java-client google-drive-api


    【解决方案1】:

    您是对的,您需要为您的文档条目添加 ACL 条目。你可以有如下方法:

    public void shareFile(DocumentListEntry documentListEntry,
            AclScope.Type type, String value, String role)
            throws MalformedURLException, IOException, ServiceException {
    
        // Instantiate a AclEntry object to update sharing permissions.
        AclEntry acl = new AclEntry();
    
        // Set the ACL scope.
        acl.setScope(new AclScope(type, value));
    
        // Set the ACL role.
        acl.setRole(new AclRole(role));
    
        // Insert the new role into the ACL feed.
        service.insert(new URL(documentListEntry.getAclFeedLink().getHref()), acl);             
    }
    

    这里 service 是 com.google.gdata.client.docs.DocsService 的一个对象。您还可以在文档上指定不同的共享typesroles

    上述方法的可能调用可以是

    shareFile(entryObj,AclScope.Type.USER,"your email id",AclRole.OWNER);
    shareFile(entryObj,AclScope.Type.DOMAIN,"domain name",AclRole.READER);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-12
      • 1970-01-01
      • 1970-01-01
      • 2016-07-11
      • 2018-10-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多