0

我有下面的代码,可以将文件上传到我的 Google 服务帐户。它正在工作,但我想知道文件在哪里?我可以使用哪个帐户登录谷歌驱动器并获取文件以及我可以使用多少空间?服务帐户是否有类似谷歌驱动器用户界面的东西?

private static Google.Apis.Drive.v2.Data.File insertFile(
      String title, 
      String mimeType, 
      MemoryStream FileStream)
    {
        String serviceAccountEmail = "XXXXXX@developer.gserviceaccount.com";

        var certificate = new X509Certificate2(
             @"XXXXXXprivatekey.p12", 
             "notasecret", 
             X509KeyStorageFlags.Exportable);

        ServiceAccountCredential credential = new ServiceAccountCredential(
           new ServiceAccountCredential.Initializer(serviceAccountEmail)
           {
               Scopes = new[] { DriveService.Scope.Drive }
           }.FromCertificate(certificate));

        // Create the service.
        DriveService service = new DriveService(
                                   new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "Drive API Sample",
        });

        // File's metadata.
        Google.Apis.Drive.v2.Data.File body = 
                  new Google.Apis.Drive.v2.Data.File();
        body.Title = title;
        body.Description = title;
        body.MimeType = mimeType;

        FilesResource.InsertMediaUpload request = 
              service.Files.Insert(body, FileStream, mimeType);
        request.Upload();

        Google.Apis.Drive.v2.Data.File file = request.ResponseBody;

        return file;
    }
4

1 回答 1

3

服务帐户没有 UI。这些文件只能由您的应用访问。

于 2014-03-07T10:17:45.697 回答