首页 文章

转让Google Cloud 端硬盘文档的所有权

提问于
浏览
1

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

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

根据文档,它在OAuth2中实现为superadmin功能 . 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:""

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

Update from 13-08-2014:

亲爱的,我觉得用户非人格化有问题 .
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:“”

如何正确地对服务帐户进行非个性化?

Updated 13-08-2014

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

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

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

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
            });
    

相关问题