1

我们用 C# 开发应用程序,该应用程序需要在未经原始所有者许可的情况下将与窗帘域相关的所有 Google Drive 文档的所有权转移给单个特定用户。我们正在使用 Google Apps 企业帐户的试用版。

原则上,我们需要这样做:http ://screencast.com/t/effVWLxL0Mr4但在 C# 代码中。

根据文档,它在 OAuth2 中实现为超级管理员功能。https://support.google.com/a/answer/1247799?hl=en (1)。但是文档已被弃用,而且我们没有找到任何 API 调用来做到这一点。

使用项目创建者的帐户,似乎他无法访问所有文件,也无法查看未与他共享的文件。

在管理 API 客户端访问的 Google 管理控制台中,我们为他添加了访问权限,以在未经许可的情况下访问文件。链接:screencast.com/t/zU9cc6Psyb。我们根据该文档链接添加了路由访问路由: trovepromo-tf.trove-stg.com/0m1-sds/support.google.com/a/answer/162106?hl=en并再次尝试。它没有成功...

此外,我们发现我们需要使用服务帐户来访问域中所有用户的所有数据,因此我们在创建的项目中生成服务帐户链接的 API 密钥: screencast.com/t/rNKuz6zchwV并在应用程序使用以下代码:

var certificate = new X509Certificate2(@"C:\Temp\key.p12", "notasecret", X509KeyStorageFlags.Exportable);

        ServiceAccountCredential credential = new ServiceAccountCredential(
           new ServiceAccountCredential.Initializer("Service account email")
           {
               User= "admin@domain.com",
               Scopes = new[] { DriveService.Scope.Drive }
           }.FromCertificate(certificate));

但是当我们尝试获取文件夹列表时,我们得到错误:“ access_denied”,描述:"Requested client not authorized.", Uri:""

请帮助我们通过服务帐户将一位用户的所有权转让给另一位用户!

2014 年 8 月 13 日更新:

亲爱的,我似乎对用户非个性化有问题。
1)当我使用api代表用户连接时。在身份验证期间,它会重定向到浏览器并请求许可。在那之后一切都很好,我可以使用文件夹进行操作,除了一件事:我不能将所有权转让给他 2)当我使用没有非个性化的服务帐户时,身份验证如下所示:

ServiceAccountCredential credential = new ServiceAccountCredential(
           new ServiceAccountCredential.Initializer(ServiceAccountId)
           {

               Scopes = new[] { DriveService.Scope.Drive, 
                                          DriveService.Scope.DriveAppdata,
                                          DriveService.Scope.DriveFile, 
                                          DriveService.Scope.DriveScripts,
                                          DirectoryService.Scope.AdminDirectoryUser,
                                          DirectoryService.Scope.AdminDirectoryGroup,
                                          DirectoryService.Scope.AdminDirectoryOrgunit,
                                          DirectoryService.Scope.AdminDirectoryUserReadonly 
                },


           }.FromCertificate(certificate));

然后我可以访问共享到服务帐户的所有文件,但(再次)我无法转移权限。

3)然后我尝试通过将 sypeadministrator 电子邮件帐户添加到用户 User = myaddress@mydomain.com 来非个人化服务帐户

ServiceAccountCredential credential = new ServiceAccountCredential(
           new ServiceAccountCredential.Initializer(ServiceAccountId)
           {

               Scopes = new[] { DriveService.Scope.Drive, 
                                          DriveService.Scope.DriveAppdata,
                                          DriveService.Scope.DriveFile, 
                                          DriveService.Scope.DriveScripts,
                                          DirectoryService.Scope.AdminDirectoryUser,
                                          DirectoryService.Scope.AdminDirectoryGroup,
                                          DirectoryService.Scope.AdminDirectoryOrgunit,
                                          DirectoryService.Scope.AdminDirectoryUserReadonly 
                },
             User = AdminEmail,

           }.FromCertificate(certificate));

然后我有错误:“access_denied”,描述:“请求的客户端未授权。”,Uri:“”

如何正确非个性化服务帐户?

2014 年 8 月 13 日更新

我们发现用于身份验证的基本 api 在这里:https ://developers.google.com/accounts/docs/OAuth2ServiceAccount#creatingjwt

通常,我之前展示的只是协议的 .net 实现。

我们如何才能在 .net 代码中对用户进行非个性化。我们没有找到任何有效的 .net 实现。

4

1 回答 1

0

我终于找到了答案。

我可以使用以下结构来非个人化帐户:

感谢所有试图帮助我的人!

        var initializer = new ServiceAccountCredential.Initializer(ServiceAccountId)
        {
            Scopes = scope,
            User = AdminEmail1
        };

        var credential = new ServiceAccountCredential(initializer.FromCertificate(certificate));

        var driveService = new DriveService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = ApplicationName
        });
于 2014-08-14T09:26:00.333 回答