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

时间:2014-08-09 12:50:59

标签: c# .net oauth-2.0 google-drive-api oauth2client

我们在C#中开发应用程序,需要在未经原始所有者许可的情况下将与窗帘域相关的所有Google云端硬盘文档的所有权转让给单个特定用户。我们正在使用试用版的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并再次尝试。  它没有成功......

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

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:“”

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

更新于13-08-2014

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

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

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

1 个答案:

答案 0 :(得分: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
        });
相关问题