如何在.NET中发布Google Docs?

时间:2012-03-19 13:17:06

标签: .net google-docs google-docs-api

我使用google-gdata .NET库与Google文档集成。它运作得很好,但我无法弄清楚如何将其用于publish my documents以进行仅基于链接的网络访问。

这背后的基本思想是能够将文档上传到Google文档,并且能够在网络环境(Google之外)中查看该文档,而无需使用Google凭据登录。据我所知,最好的方法是通过秘密链接发布它,如上面链接的帮助文章所述。

那么有谁知道如何在.NET中以编程方式发布Google Docs?

修改

作为参考点,并且为了说明更改文档上的ACL(即公开)和发布文档本身(如上面描述的链接所描述)之间的区别,这些是相应的版本Google文档中的同一文档:

2 个答案:

答案 0 :(得分:3)

我刚刚更新了.NET客户端库,现在您可以使用以下代码发布修订版(它假定entry是您要发布的DocumentEntry实例):

RevisionQuery revisionQuery = new RevisionQuery(entry.RevisionDocument);
RevisionFeed revisions = service.Query(revisionQuery);

// TODO: choose the revision you want to publish, this sample selects the first one
RevisionEntry revision = (RevisionEntry)revisions.Entries[0];

revision.Publish = true;
revision.PublishAuto = true;

revision.Update();

答案 1 :(得分:2)

您的问题已经在包含Java代码段的post上得到了解答。 对于.NET,你应该可以做类似的事情:

AclEntry aclEntry = new AclEntry();
aclEntry.Role = new AclRole("reader");
aclEntry.Scope = new AclScope(AclScope.SCOPE_DEFAULT);

// documentEntry is the document that you want to publish and service is an 
// authorized DocumentsService object.
AclEntry insertedEntry = service.Insert(
    new Uri(documentEntry.AccessControlList), aclEntry);