0

我想爲Google Documents List API創建一個Android客戶端應用程序,同時考慮到它可能會在不久的將來被Google Drive API取代。因此,我使用google-api-java-client實現了身份驗證,如果需要,可能會輕鬆過渡到新的API。如何在Android上使用google-api-java-client共享文檔?

現在我試圖擴展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

從谷歌文檔列表API文檔,我想通了ACL是用來給其他用戶訪問特定的文檔。但是,我不清楚應該實現哪些方法來實現這個或其他常見的API相關事務。

回答

0

您是對的,您需要爲您的文檔條目添加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);    
} 

這裏服務是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); 
相關問題