如何使用 .net google sheet API 在 Google spreadsheet 中设置“发布到网络”?

How to Set “publish to web” in Google spreadsheet using .net google sheet API?

我正在使用 google sheet api 创建 sheets 并希望为 sheet 嵌入 iframe link。

ServiceAccountCredential credential = new ServiceAccountCredential(
                new ServiceAccountCredential.Initializer(serviceAccountEmail)
                {
                    Scopes = new[] { SheetsService.Scope.Spreadsheets,DriveService.Scope.DriveFile}
                }.FromCertificate(certificate));
            BaseClientService.Initializer clientService = new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = ApplicationName,
            };
            var service = new SheetsService(clientService);
            var spareSheet = new Spreadsheet();
            spareSheet.Properties = new SpreadsheetProperties();
            spareSheet.Properties.Title = "TestSheet";

            spareSheet = service.Spreadsheets.Create(spareSheet).Execute();  
 var driveService = new DriveService(clientService);


            var fileMetadata = new Google.Apis.Drive.v3.Data.File();
            fileMetadata.Name = fileName;
            fileMetadata.MimeType = "application/vnd.google-apps.spreadsheet";
            var fileRequest = driveService.Files.Create(fileMetadata);
            fileRequest.Fields = "id";
            var file = fileRequest.Execute();
            Console.WriteLine("File ID: " + file.Id);
           // Console.WriteLine("URL"+file.)
            Permission userPermission = new Permission();
            userPermission.Type = "anyone";
            userPermission.Role = "writer";
            //   userPermission.we
            var revision = new Revision();
            revision.PublishAuto = true;
            revision.Published = true;
            revision.PublishedOutsideDomain = true;
            driveService.Permissions.Create(userPermission, file.Id).Execute();
            var request = driveService.Revisions.Update(revision, file.Id, "head");
            request.Execute();
string iframeURl="<iframe src='https://docs.google.com/spreadsheets/d/"+file.Id+"/edit?rm=minimal#gid=1333667591' height='900' width='800'></iframe>";