Skip to content

Instantly share code, notes, and snippets.

@LindaLawton
Created May 15, 2020 09:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LindaLawton/37cd45d8d3b091a6d0844856e61e8834 to your computer and use it in GitHub Desktop.
Save LindaLawton/37cd45d8d3b091a6d0844856e61e8834 to your computer and use it in GitHub Desktop.
Google drive v3 samples C#
using Google.Apis.Drive.v3;
using Google.Apis.Drive.v3.Data;
using System;
using Google.Apis.Requests;
namespace GoogleApiSample.Drivev3
{
public static class AboutExamples
{
public class GetAboutOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
}
/// <summary>
/// Gets information about the user, the user's Drive, and system capabilities.
/// </summary>
/// <param name="service"></param>
/// <param name="options"></param>
/// <returns></returns>
public static About GetAbout(DriveService service, GetAboutOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
return service.About.Get().Execute();
}
catch (Exception ex)
{
throw new Exception($"Request About.Get failed with message {ex.Message}", ex);
}
}
}
}
using Google.Apis.Drive.v3;
using Google.Apis.Drive.v3.Data;
using System;
using Google.Apis.Requests;
namespace GoogleApiSample.Drivev3
{
public static class ChangesExamples
{
public class GetStartPageTokenChangesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Gets the starting pageToken for listing future changes.
/// </summary>
public string DriveId { get; set; }
/// <summary>
/// Gets the starting pageToken for listing future changes.
/// </summary>
public bool SupportsAllDrives { get; set; }
/// <summary>
/// Gets the starting pageToken for listing future changes.
/// </summary>
public bool SupportsTeamDrives { get; set; }
/// <summary>
/// Gets the starting pageToken for listing future changes.
/// </summary>
public string TeamDriveId { get; set; }
}
/// <summary>
/// Gets the starting pageToken for listing future changes.
/// </summary>
/// <param name="service"></param>
/// <param name="options"></param>
/// <returns></returns>
public static StartPageToken GetStartPageTokenChanges(DriveService service, GetStartPageTokenChangesOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
return service.Changes.GetStartPageToken().Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Changes.GetStartPageToken failed with message {ex.Message}", ex);
}
}
public class ListChangesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Lists the changes for a user or shared drive.
/// </summary>
public string DriveId { get; set; }
/// <summary>
/// Lists the changes for a user or shared drive.
/// </summary>
public bool IncludeCorpusRemovals { get; set; }
/// <summary>
/// Lists the changes for a user or shared drive.
/// </summary>
public bool IncludeItemsFromAllDrives { get; set; }
/// <summary>
/// Lists the changes for a user or shared drive.
/// </summary>
public bool IncludeRemoved { get; set; }
/// <summary>
/// Lists the changes for a user or shared drive.
/// </summary>
public bool IncludeTeamDriveItems { get; set; }
/// <summary>
/// Lists the changes for a user or shared drive.
/// </summary>
public int PageSize { get; set; }
/// <summary>
/// Lists the changes for a user or shared drive.
/// </summary>
public string PageToken { get; set; }
/// <summary>
/// Lists the changes for a user or shared drive.
/// </summary>
public bool RestrictToMyDrive { get; set; }
/// <summary>
/// Lists the changes for a user or shared drive.
/// </summary>
public string Spaces { get; set; }
/// <summary>
/// Lists the changes for a user or shared drive.
/// </summary>
public bool SupportsAllDrives { get; set; }
/// <summary>
/// Lists the changes for a user or shared drive.
/// </summary>
public bool SupportsTeamDrives { get; set; }
/// <summary>
/// Lists the changes for a user or shared drive.
/// </summary>
public string TeamDriveId { get; set; }
}
/// <summary>
/// Lists the changes for a user or shared drive.
/// </summary>
/// <param name="service"></param>
/// <param name="pageToken">The token for continuing a previous list request on the next page. This should be set to the value of 'nextPageToken' from the previous response or to the response from the getStartPageToken method.</param>
/// <param name="options"></param>
/// <returns></returns>
public static ChangeList ListChanges(DriveService service, string pageToken, ListChangesOptionalParameters options)
{
var result = new ChangeList();
var request = service.Changes.List(pageToken);
do {
try
{
return request.Execute();
}
catch (Exception e)
{
Console.WriteLine("An error occurred: " + e.Message);
}
} while (!String.IsNullOrEmpty(request.PageToken));
return result;
}
public class WatchChangesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Subscribes to changes for a user.
/// </summary>
public string DriveId { get; set; }
/// <summary>
/// Subscribes to changes for a user.
/// </summary>
public bool IncludeCorpusRemovals { get; set; }
/// <summary>
/// Subscribes to changes for a user.
/// </summary>
public bool IncludeItemsFromAllDrives { get; set; }
/// <summary>
/// Subscribes to changes for a user.
/// </summary>
public bool IncludeRemoved { get; set; }
/// <summary>
/// Subscribes to changes for a user.
/// </summary>
public bool IncludeTeamDriveItems { get; set; }
/// <summary>
/// Subscribes to changes for a user.
/// </summary>
public int PageSize { get; set; }
/// <summary>
/// Subscribes to changes for a user.
/// </summary>
public string PageToken { get; set; }
/// <summary>
/// Subscribes to changes for a user.
/// </summary>
public bool RestrictToMyDrive { get; set; }
/// <summary>
/// Subscribes to changes for a user.
/// </summary>
public string Spaces { get; set; }
/// <summary>
/// Subscribes to changes for a user.
/// </summary>
public bool SupportsAllDrives { get; set; }
/// <summary>
/// Subscribes to changes for a user.
/// </summary>
public bool SupportsTeamDrives { get; set; }
/// <summary>
/// Subscribes to changes for a user.
/// </summary>
public string TeamDriveId { get; set; }
}
/// <summary>
/// Subscribes to changes for a user.
/// </summary>
/// <param name="service"></param>
/// <param name="body"></param>
/// <param name="pageToken">The token for continuing a previous list request on the next page. This should be set to the value of 'nextPageToken' from the previous response or to the response from the getStartPageToken method.</param>
/// <param name="options"></param>
/// <returns></returns>
public static Channel WatchChanges(DriveService service, Channel body, string pageToken, WatchChangesOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
return service.Changes.Watch(body, pageToken).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Changes.Watch failed with message {ex.Message}", ex);
}
}
}
}
using Google.Apis.Drive.v3;
using Google.Apis.Drive.v3.Data;
using System;
using Google.Apis.Requests;
namespace GoogleApiSample.Drivev3
{
public static class ChannelsExamples
{
public class StopChannelsOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
}
/// <summary>
/// Stop watching resources through this channel
/// </summary>
/// <param name="service"></param>
/// <param name="body"></param>
/// <param name="options"></param>
/// <returns></returns>
public static void StopChannels(DriveService service, Channel body, StopChannelsOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
service.Channels.Stop(body).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Channels.Stop failed with message {ex.Message}", ex);
}
}
}
}
using Google.Apis.Drive.v3;
using Google.Apis.Drive.v3.Data;
using System;
using Google.Apis.Requests;
namespace GoogleApiSample.Drivev3
{
public static class CommentsExamples
{
public class CreateCommentsOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Creates a new comment on a file.
/// </summary>
public string FileId { get; set; }
}
/// <summary>
/// Creates a new comment on a file.
/// </summary>
/// <param name="service"></param>
/// <param name="body"></param>
/// <param name="fileId">The ID of the file.</param>
/// <param name="options"></param>
/// <returns></returns>
public static Comment CreateComments(DriveService service, Comment body, string fileId, CreateCommentsOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
return service.Comments.Create(body, fileId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Comments.Create failed with message {ex.Message}", ex);
}
}
public class DeleteCommentsOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Deletes a comment.
/// </summary>
public string CommentId { get; set; }
/// <summary>
/// Deletes a comment.
/// </summary>
public string FileId { get; set; }
}
/// <summary>
/// Deletes a comment.
/// </summary>
/// <param name="service"></param>
/// <param name="fileId">The ID of the file.</param>
/// <param name="commentId">The ID of the comment.</param>
/// <param name="options"></param>
/// <returns></returns>
public static void DeleteComments(DriveService service, string fileId, string commentId, DeleteCommentsOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
service.Comments.Delete(fileId, commentId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Comments.Delete failed with message {ex.Message}", ex);
}
}
public class GetCommentsOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Gets a comment by ID.
/// </summary>
public string CommentId { get; set; }
/// <summary>
/// Gets a comment by ID.
/// </summary>
public string FileId { get; set; }
/// <summary>
/// Gets a comment by ID.
/// </summary>
public bool IncludeDeleted { get; set; }
}
/// <summary>
/// Gets a comment by ID.
/// </summary>
/// <param name="service"></param>
/// <param name="fileId">The ID of the file.</param>
/// <param name="commentId">The ID of the comment.</param>
/// <param name="options"></param>
/// <returns></returns>
public static Comment GetComments(DriveService service, string fileId, string commentId, GetCommentsOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
return service.Comments.Get(fileId, commentId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Comments.Get failed with message {ex.Message}", ex);
}
}
public class ListCommentsOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Lists a file's comments.
/// </summary>
public string FileId { get; set; }
/// <summary>
/// Lists a file's comments.
/// </summary>
public bool IncludeDeleted { get; set; }
/// <summary>
/// Lists a file's comments.
/// </summary>
public int PageSize { get; set; }
/// <summary>
/// Lists a file's comments.
/// </summary>
public string PageToken { get; set; }
/// <summary>
/// Lists a file's comments.
/// </summary>
public string StartModifiedTime { get; set; }
}
/// <summary>
/// Lists a file's comments.
/// </summary>
/// <param name="service"></param>
/// <param name="fileId">The ID of the file.</param>
/// <param name="options"></param>
/// <returns></returns>
public static CommentList ListComments(DriveService service, string fileId, ListCommentsOptionalParameters options)
{
// A page streamer is a helper to provide both synchronous and asynchronous page streaming
// of a listable or queryable resource.
var pageStreamer =
new PageStreamer<Comment, CommentsResource.ListRequest, CommentList, string>(
(request, token) => request.PageToken = token,
response => response.NextPageToken, response => response.Comments);
try
{
var results = new CommentList();
var request = service.Comments.List(fileId);
// iterate through the results
foreach (var result in pageStreamer.Fetch(request))
{
results.Comments.Add(result);
}
return results;
}
catch (Exception ex)
{
throw new Exception($"Request Comments.List failed with message {ex.Message}", ex);
}
}
public class UpdateCommentsOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Updates a comment with patch semantics.
/// </summary>
public string CommentId { get; set; }
/// <summary>
/// Updates a comment with patch semantics.
/// </summary>
public string FileId { get; set; }
}
/// <summary>
/// Updates a comment with patch semantics.
/// </summary>
/// <param name="service"></param>
/// <param name="body"></param>
/// <param name="fileId">The ID of the file.</param>
/// <param name="commentId">The ID of the comment.</param>
/// <param name="options"></param>
/// <returns></returns>
public static Comment UpdateComments(DriveService service, Comment body, string fileId, string commentId, UpdateCommentsOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
return service.Comments.Update(body, fileId, commentId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Comments.Update failed with message {ex.Message}", ex);
}
}
}
}
using Google.Apis.Drive.v3;
using Google.Apis.Drive.v3.Data;
using System;
using Google.Apis.Requests;
namespace GoogleApiSample.Drivev3
{
public static class DrivesExamples
{
public class CreateDrivesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Creates a new shared drive.
/// </summary>
public string RequestId { get; set; }
}
/// <summary>
/// Creates a new shared drive.
/// </summary>
/// <param name="service"></param>
/// <param name="body"></param>
/// <param name="requestId">An ID, such as a random UUID, which uniquely identifies this user's request for idempotent creation of a shared drive. A repeated request by the same user and with the same request ID will avoid creating duplicates by attempting to create the same shared drive. If the shared drive already exists a 409 error will be returned.</param>
/// <param name="options"></param>
/// <returns></returns>
public static Drive CreateDrives(DriveService service, Drive body, string requestId, CreateDrivesOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
return service.Drives.Create(body, requestId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Drives.Create failed with message {ex.Message}", ex);
}
}
public class DeleteDrivesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Permanently deletes a shared drive for which the user is an organizer. The shared drive cannot contain any untrashed items.
/// </summary>
public string DriveId { get; set; }
}
/// <summary>
/// Permanently deletes a shared drive for which the user is an organizer. The shared drive cannot contain any untrashed items.
/// </summary>
/// <param name="service"></param>
/// <param name="driveId">The ID of the shared drive.</param>
/// <param name="options"></param>
/// <returns></returns>
public static void DeleteDrives(DriveService service, string driveId, DeleteDrivesOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
service.Drives.Delete(driveId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Drives.Delete failed with message {ex.Message}", ex);
}
}
public class GetDrivesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Gets a shared drive's metadata by ID.
/// </summary>
public string DriveId { get; set; }
/// <summary>
/// Gets a shared drive's metadata by ID.
/// </summary>
public bool UseDomainAdminAccess { get; set; }
}
/// <summary>
/// Gets a shared drive's metadata by ID.
/// </summary>
/// <param name="service"></param>
/// <param name="driveId">The ID of the shared drive.</param>
/// <param name="options"></param>
/// <returns></returns>
public static Drive GetDrives(DriveService service, string driveId, GetDrivesOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
return service.Drives.Get(driveId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Drives.Get failed with message {ex.Message}", ex);
}
}
public class HideDrivesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Hides a shared drive from the default view.
/// </summary>
public string DriveId { get; set; }
}
/// <summary>
/// Hides a shared drive from the default view.
/// </summary>
/// <param name="service"></param>
/// <param name="body"></param>
/// <param name="driveId">The ID of the shared drive.</param>
/// <param name="options"></param>
/// <returns></returns>
public static Drive HideDrives(DriveService service, body, string driveId, HideDrivesOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
return service.Drives.Hide(body, driveId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Drives.Hide failed with message {ex.Message}", ex);
}
}
public class ListDrivesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Lists the user's shared drives.
/// </summary>
public int PageSize { get; set; }
/// <summary>
/// Lists the user's shared drives.
/// </summary>
public string PageToken { get; set; }
/// <summary>
/// Lists the user's shared drives.
/// </summary>
public string Q { get; set; }
/// <summary>
/// Lists the user's shared drives.
/// </summary>
public bool UseDomainAdminAccess { get; set; }
}
/// <summary>
/// Lists the user's shared drives.
/// </summary>
/// <param name="service"></param>
/// <param name="options"></param>
/// <returns></returns>
public static DriveList ListDrives(DriveService service, ListDrivesOptionalParameters options)
{
// A page streamer is a helper to provide both synchronous and asynchronous page streaming
// of a listable or queryable resource.
var pageStreamer =
new PageStreamer<Drive, DrivesResource.ListRequest, DriveList, string>(
(request, token) => request.PageToken = token,
response => response.NextPageToken, response => response.Drives);
try
{
var results = new DriveList();
var request = service.Drives.List();
// iterate through the results
foreach (var result in pageStreamer.Fetch(request))
{
results.Drives.Add(result);
}
return results;
}
catch (Exception ex)
{
throw new Exception($"Request Drives.List failed with message {ex.Message}", ex);
}
}
public class UnhideDrivesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Restores a shared drive to the default view.
/// </summary>
public string DriveId { get; set; }
}
/// <summary>
/// Restores a shared drive to the default view.
/// </summary>
/// <param name="service"></param>
/// <param name="body"></param>
/// <param name="driveId">The ID of the shared drive.</param>
/// <param name="options"></param>
/// <returns></returns>
public static Drive UnhideDrives(DriveService service, body, string driveId, UnhideDrivesOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
return service.Drives.Unhide(body, driveId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Drives.Unhide failed with message {ex.Message}", ex);
}
}
public class UpdateDrivesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Updates the metadate for a shared drive.
/// </summary>
public string DriveId { get; set; }
/// <summary>
/// Updates the metadate for a shared drive.
/// </summary>
public bool UseDomainAdminAccess { get; set; }
}
/// <summary>
/// Updates the metadate for a shared drive.
/// </summary>
/// <param name="service"></param>
/// <param name="body"></param>
/// <param name="driveId">The ID of the shared drive.</param>
/// <param name="options"></param>
/// <returns></returns>
public static Drive UpdateDrives(DriveService service, Drive body, string driveId, UpdateDrivesOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
return service.Drives.Update(body, driveId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Drives.Update failed with message {ex.Message}", ex);
}
}
}
}
using Google.Apis.Drive.v3;
using Google.Apis.Drive.v3.Data;
using System;
using Google.Apis.Requests;
namespace GoogleApiSample.Drivev3
{
public static class FilesExamples
{
public class CopyFilesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Creates a copy of a file and applies any requested updates with patch semantics.
/// </summary>
public bool EnforceSingleParent { get; set; }
/// <summary>
/// Creates a copy of a file and applies any requested updates with patch semantics.
/// </summary>
public string FileId { get; set; }
/// <summary>
/// Creates a copy of a file and applies any requested updates with patch semantics.
/// </summary>
public bool IgnoreDefaultVisibility { get; set; }
/// <summary>
/// Creates a copy of a file and applies any requested updates with patch semantics.
/// </summary>
public bool KeepRevisionForever { get; set; }
/// <summary>
/// Creates a copy of a file and applies any requested updates with patch semantics.
/// </summary>
public string OcrLanguage { get; set; }
/// <summary>
/// Creates a copy of a file and applies any requested updates with patch semantics.
/// </summary>
public bool SupportsAllDrives { get; set; }
/// <summary>
/// Creates a copy of a file and applies any requested updates with patch semantics.
/// </summary>
public bool SupportsTeamDrives { get; set; }
}
/// <summary>
/// Creates a copy of a file and applies any requested updates with patch semantics.
/// </summary>
/// <param name="service"></param>
/// <param name="body"></param>
/// <param name="fileId">The ID of the file.</param>
/// <param name="options"></param>
/// <returns></returns>
public static File CopyFiles(DriveService service, File body, string fileId, CopyFilesOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
return service.Files.Copy(body, fileId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Files.Copy failed with message {ex.Message}", ex);
}
}
public class CreateFilesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Creates a new file.
/// </summary>
public bool EnforceSingleParent { get; set; }
/// <summary>
/// Creates a new file.
/// </summary>
public bool IgnoreDefaultVisibility { get; set; }
/// <summary>
/// Creates a new file.
/// </summary>
public bool KeepRevisionForever { get; set; }
/// <summary>
/// Creates a new file.
/// </summary>
public string OcrLanguage { get; set; }
/// <summary>
/// Creates a new file.
/// </summary>
public bool SupportsAllDrives { get; set; }
/// <summary>
/// Creates a new file.
/// </summary>
public bool SupportsTeamDrives { get; set; }
/// <summary>
/// Creates a new file.
/// </summary>
public bool UseContentAsIndexableText { get; set; }
}
/// <summary>
/// Creates a new file.
/// </summary>
/// <param name="service"></param>
/// <param name="body"></param>
/// <param name="options"></param>
/// <returns></returns>
public static File CreateFiles(DriveService service, File body, CreateFilesOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
return service.Files.Create(body).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Files.Create failed with message {ex.Message}", ex);
}
}
public class DeleteFilesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Permanently deletes a file owned by the user without moving it to the trash. If the file belongs to a shared drive the user must be an organizer on the parent. If the target is a folder, all descendants owned by the user are also deleted.
/// </summary>
public string FileId { get; set; }
/// <summary>
/// Permanently deletes a file owned by the user without moving it to the trash. If the file belongs to a shared drive the user must be an organizer on the parent. If the target is a folder, all descendants owned by the user are also deleted.
/// </summary>
public bool SupportsAllDrives { get; set; }
/// <summary>
/// Permanently deletes a file owned by the user without moving it to the trash. If the file belongs to a shared drive the user must be an organizer on the parent. If the target is a folder, all descendants owned by the user are also deleted.
/// </summary>
public bool SupportsTeamDrives { get; set; }
}
/// <summary>
/// Permanently deletes a file owned by the user without moving it to the trash. If the file belongs to a shared drive the user must be an organizer on the parent. If the target is a folder, all descendants owned by the user are also deleted.
/// </summary>
/// <param name="service"></param>
/// <param name="fileId">The ID of the file.</param>
/// <param name="options"></param>
/// <returns></returns>
public static void DeleteFiles(DriveService service, string fileId, DeleteFilesOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
service.Files.Delete(fileId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Files.Delete failed with message {ex.Message}", ex);
}
}
public class EmptyTrashFilesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
}
/// <summary>
/// Permanently deletes all of the user's trashed files.
/// </summary>
/// <param name="service"></param>
/// <param name="options"></param>
/// <returns></returns>
public static void EmptyTrashFiles(DriveService service, EmptyTrashFilesOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
service.Files.EmptyTrash().Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Files.EmptyTrash failed with message {ex.Message}", ex);
}
}
public class ExportFilesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Exports a Google Doc to the requested MIME type and returns the exported content. Please note that the exported content is limited to 10MB.
/// </summary>
public string FileId { get; set; }
/// <summary>
/// Exports a Google Doc to the requested MIME type and returns the exported content. Please note that the exported content is limited to 10MB.
/// </summary>
public string MimeType { get; set; }
}
/// <summary>
/// Exports a Google Doc to the requested MIME type and returns the exported content. Please note that the exported content is limited to 10MB.
/// </summary>
/// <param name="service"></param>
/// <param name="fileId">The ID of the file.</param>
/// <param name="mimeType">The MIME type of the format requested for this export.</param>
/// <param name="options"></param>
/// <returns></returns>
public static void ExportFiles(DriveService service, string fileId, string mimeType, ExportFilesOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
service.Files.Export(fileId, mimeType).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Files.Export failed with message {ex.Message}", ex);
}
}
public class GenerateIdsFilesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Generates a set of file IDs which can be provided in create or copy requests.
/// </summary>
public int Count { get; set; }
/// <summary>
/// Generates a set of file IDs which can be provided in create or copy requests.
/// </summary>
public string Space { get; set; }
}
/// <summary>
/// Generates a set of file IDs which can be provided in create or copy requests.
/// </summary>
/// <param name="service"></param>
/// <param name="options"></param>
/// <returns></returns>
public static GeneratedIds GenerateIdsFiles(DriveService service, GenerateIdsFilesOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
return service.Files.GenerateIds().Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Files.GenerateIds failed with message {ex.Message}", ex);
}
}
public class GetFilesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Gets a file's metadata or content by ID.
/// </summary>
public bool AcknowledgeAbuse { get; set; }
/// <summary>
/// Gets a file's metadata or content by ID.
/// </summary>
public string FileId { get; set; }
/// <summary>
/// Gets a file's metadata or content by ID.
/// </summary>
public bool SupportsAllDrives { get; set; }
/// <summary>
/// Gets a file's metadata or content by ID.
/// </summary>
public bool SupportsTeamDrives { get; set; }
}
/// <summary>
/// Gets a file's metadata or content by ID.
/// </summary>
/// <param name="service"></param>
/// <param name="fileId">The ID of the file.</param>
/// <param name="options"></param>
/// <returns></returns>
public static File GetFiles(DriveService service, string fileId, GetFilesOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
return service.Files.Get(fileId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Files.Get failed with message {ex.Message}", ex);
}
}
public class ListFilesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Lists or searches files.
/// </summary>
public string Corpora { get; set; }
/// <summary>
/// Lists or searches files.
/// </summary>
public string Corpus { get; set; }
/// <summary>
/// Lists or searches files.
/// </summary>
public string DriveId { get; set; }
/// <summary>
/// Lists or searches files.
/// </summary>
public bool IncludeItemsFromAllDrives { get; set; }
/// <summary>
/// Lists or searches files.
/// </summary>
public bool IncludeTeamDriveItems { get; set; }
/// <summary>
/// Lists or searches files.
/// </summary>
public string OrderBy { get; set; }
/// <summary>
/// Lists or searches files.
/// </summary>
public int PageSize { get; set; }
/// <summary>
/// Lists or searches files.
/// </summary>
public string PageToken { get; set; }
/// <summary>
/// Lists or searches files.
/// </summary>
public string Q { get; set; }
/// <summary>
/// Lists or searches files.
/// </summary>
public string Spaces { get; set; }
/// <summary>
/// Lists or searches files.
/// </summary>
public bool SupportsAllDrives { get; set; }
/// <summary>
/// Lists or searches files.
/// </summary>
public bool SupportsTeamDrives { get; set; }
/// <summary>
/// Lists or searches files.
/// </summary>
public string TeamDriveId { get; set; }
}
/// <summary>
/// Lists or searches files.
/// </summary>
/// <param name="service"></param>
/// <param name="options"></param>
/// <returns></returns>
public static FileList ListFiles(DriveService service, ListFilesOptionalParameters options)
{
// A page streamer is a helper to provide both synchronous and asynchronous page streaming
// of a listable or queryable resource.
var pageStreamer =
new PageStreamer<File, FilesResource.ListRequest, FileList, string>(
(request, token) => request.PageToken = token,
response => response.NextPageToken, response => response.Files);
try
{
var results = new FileList();
var request = service.Files.List();
// iterate through the results
foreach (var result in pageStreamer.Fetch(request))
{
results.Files.Add(result);
}
return results;
}
catch (Exception ex)
{
throw new Exception($"Request Files.List failed with message {ex.Message}", ex);
}
}
public class UpdateFilesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Updates a file's metadata and/or content with patch semantics.
/// </summary>
public string AddParents { get; set; }
/// <summary>
/// Updates a file's metadata and/or content with patch semantics.
/// </summary>
public bool EnforceSingleParent { get; set; }
/// <summary>
/// Updates a file's metadata and/or content with patch semantics.
/// </summary>
public string FileId { get; set; }
/// <summary>
/// Updates a file's metadata and/or content with patch semantics.
/// </summary>
public bool KeepRevisionForever { get; set; }
/// <summary>
/// Updates a file's metadata and/or content with patch semantics.
/// </summary>
public string OcrLanguage { get; set; }
/// <summary>
/// Updates a file's metadata and/or content with patch semantics.
/// </summary>
public string RemoveParents { get; set; }
/// <summary>
/// Updates a file's metadata and/or content with patch semantics.
/// </summary>
public bool SupportsAllDrives { get; set; }
/// <summary>
/// Updates a file's metadata and/or content with patch semantics.
/// </summary>
public bool SupportsTeamDrives { get; set; }
/// <summary>
/// Updates a file's metadata and/or content with patch semantics.
/// </summary>
public bool UseContentAsIndexableText { get; set; }
}
/// <summary>
/// Updates a file's metadata and/or content with patch semantics.
/// </summary>
/// <param name="service"></param>
/// <param name="body"></param>
/// <param name="fileId">The ID of the file.</param>
/// <param name="options"></param>
/// <returns></returns>
public static File UpdateFiles(DriveService service, File body, string fileId, UpdateFilesOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
return service.Files.Update(body, fileId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Files.Update failed with message {ex.Message}", ex);
}
}
public class WatchFilesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Subscribes to changes to a file
/// </summary>
public bool AcknowledgeAbuse { get; set; }
/// <summary>
/// Subscribes to changes to a file
/// </summary>
public string FileId { get; set; }
/// <summary>
/// Subscribes to changes to a file
/// </summary>
public bool SupportsAllDrives { get; set; }
/// <summary>
/// Subscribes to changes to a file
/// </summary>
public bool SupportsTeamDrives { get; set; }
}
/// <summary>
/// Subscribes to changes to a file
/// </summary>
/// <param name="service"></param>
/// <param name="body"></param>
/// <param name="fileId">The ID of the file.</param>
/// <param name="options"></param>
/// <returns></returns>
public static Channel WatchFiles(DriveService service, Channel body, string fileId, WatchFilesOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
return service.Files.Watch(body, fileId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Files.Watch failed with message {ex.Message}", ex);
}
}
}
}
using Google.Apis.Drive.v3;
using Google.Apis.Drive.v3.Data;
using System;
using Google.Apis.Requests;
namespace GoogleApiSample.Drivev3
{
public static class PermissionsExamples
{
public class CreatePermissionsOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Creates a permission for a file or shared drive.
/// </summary>
public string EmailMessage { get; set; }
/// <summary>
/// Creates a permission for a file or shared drive.
/// </summary>
public bool EnforceSingleParent { get; set; }
/// <summary>
/// Creates a permission for a file or shared drive.
/// </summary>
public string FileId { get; set; }
/// <summary>
/// Creates a permission for a file or shared drive.
/// </summary>
public bool MoveToNewOwnersRoot { get; set; }
/// <summary>
/// Creates a permission for a file or shared drive.
/// </summary>
public bool SendNotificationEmail { get; set; }
/// <summary>
/// Creates a permission for a file or shared drive.
/// </summary>
public bool SupportsAllDrives { get; set; }
/// <summary>
/// Creates a permission for a file or shared drive.
/// </summary>
public bool SupportsTeamDrives { get; set; }
/// <summary>
/// Creates a permission for a file or shared drive.
/// </summary>
public bool TransferOwnership { get; set; }
/// <summary>
/// Creates a permission for a file or shared drive.
/// </summary>
public bool UseDomainAdminAccess { get; set; }
}
/// <summary>
/// Creates a permission for a file or shared drive.
/// </summary>
/// <param name="service"></param>
/// <param name="body"></param>
/// <param name="fileId">The ID of the file or shared drive.</param>
/// <param name="options"></param>
/// <returns></returns>
public static Permission CreatePermissions(DriveService service, Permission body, string fileId, CreatePermissionsOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
return service.Permissions.Create(body, fileId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Permissions.Create failed with message {ex.Message}", ex);
}
}
public class DeletePermissionsOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Deletes a permission.
/// </summary>
public string FileId { get; set; }
/// <summary>
/// Deletes a permission.
/// </summary>
public string PermissionId { get; set; }
/// <summary>
/// Deletes a permission.
/// </summary>
public bool SupportsAllDrives { get; set; }
/// <summary>
/// Deletes a permission.
/// </summary>
public bool SupportsTeamDrives { get; set; }
/// <summary>
/// Deletes a permission.
/// </summary>
public bool UseDomainAdminAccess { get; set; }
}
/// <summary>
/// Deletes a permission.
/// </summary>
/// <param name="service"></param>
/// <param name="fileId">The ID of the file or shared drive.</param>
/// <param name="permissionId">The ID of the permission.</param>
/// <param name="options"></param>
/// <returns></returns>
public static void DeletePermissions(DriveService service, string fileId, string permissionId, DeletePermissionsOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
service.Permissions.Delete(fileId, permissionId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Permissions.Delete failed with message {ex.Message}", ex);
}
}
public class GetPermissionsOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Gets a permission by ID.
/// </summary>
public string FileId { get; set; }
/// <summary>
/// Gets a permission by ID.
/// </summary>
public string PermissionId { get; set; }
/// <summary>
/// Gets a permission by ID.
/// </summary>
public bool SupportsAllDrives { get; set; }
/// <summary>
/// Gets a permission by ID.
/// </summary>
public bool SupportsTeamDrives { get; set; }
/// <summary>
/// Gets a permission by ID.
/// </summary>
public bool UseDomainAdminAccess { get; set; }
}
/// <summary>
/// Gets a permission by ID.
/// </summary>
/// <param name="service"></param>
/// <param name="fileId">The ID of the file.</param>
/// <param name="permissionId">The ID of the permission.</param>
/// <param name="options"></param>
/// <returns></returns>
public static Permission GetPermissions(DriveService service, string fileId, string permissionId, GetPermissionsOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
return service.Permissions.Get(fileId, permissionId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Permissions.Get failed with message {ex.Message}", ex);
}
}
public class ListPermissionsOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Lists a file's or shared drive's permissions.
/// </summary>
public string FileId { get; set; }
/// <summary>
/// Lists a file's or shared drive's permissions.
/// </summary>
public int PageSize { get; set; }
/// <summary>
/// Lists a file's or shared drive's permissions.
/// </summary>
public string PageToken { get; set; }
/// <summary>
/// Lists a file's or shared drive's permissions.
/// </summary>
public bool SupportsAllDrives { get; set; }
/// <summary>
/// Lists a file's or shared drive's permissions.
/// </summary>
public bool SupportsTeamDrives { get; set; }
/// <summary>
/// Lists a file's or shared drive's permissions.
/// </summary>
public bool UseDomainAdminAccess { get; set; }
}
/// <summary>
/// Lists a file's or shared drive's permissions.
/// </summary>
/// <param name="service"></param>
/// <param name="fileId">The ID of the file or shared drive.</param>
/// <param name="options"></param>
/// <returns></returns>
public static PermissionList ListPermissions(DriveService service, string fileId, ListPermissionsOptionalParameters options)
{
// A page streamer is a helper to provide both synchronous and asynchronous page streaming
// of a listable or queryable resource.
var pageStreamer =
new PageStreamer<Permission, PermissionsResource.ListRequest, PermissionList, string>(
(request, token) => request.PageToken = token,
response => response.NextPageToken, response => response.Permissions);
try
{
var results = new PermissionList();
var request = service.Permissions.List(fileId);
// iterate through the results
foreach (var result in pageStreamer.Fetch(request))
{
results.Permissions.Add(result);
}
return results;
}
catch (Exception ex)
{
throw new Exception($"Request Permissions.List failed with message {ex.Message}", ex);
}
}
public class UpdatePermissionsOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Updates a permission with patch semantics.
/// </summary>
public string FileId { get; set; }
/// <summary>
/// Updates a permission with patch semantics.
/// </summary>
public string PermissionId { get; set; }
/// <summary>
/// Updates a permission with patch semantics.
/// </summary>
public bool RemoveExpiration { get; set; }
/// <summary>
/// Updates a permission with patch semantics.
/// </summary>
public bool SupportsAllDrives { get; set; }
/// <summary>
/// Updates a permission with patch semantics.
/// </summary>
public bool SupportsTeamDrives { get; set; }
/// <summary>
/// Updates a permission with patch semantics.
/// </summary>
public bool TransferOwnership { get; set; }
/// <summary>
/// Updates a permission with patch semantics.
/// </summary>
public bool UseDomainAdminAccess { get; set; }
}
/// <summary>
/// Updates a permission with patch semantics.
/// </summary>
/// <param name="service"></param>
/// <param name="body"></param>
/// <param name="fileId">The ID of the file or shared drive.</param>
/// <param name="permissionId">The ID of the permission.</param>
/// <param name="options"></param>
/// <returns></returns>
public static Permission UpdatePermissions(DriveService service, Permission body, string fileId, string permissionId, UpdatePermissionsOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
return service.Permissions.Update(body, fileId, permissionId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Permissions.Update failed with message {ex.Message}", ex);
}
}
}
}
using Google.Apis.Drive.v3;
using Google.Apis.Drive.v3.Data;
using System;
using Google.Apis.Requests;
namespace GoogleApiSample.Drivev3
{
public static class RepliesExamples
{
public class CreateRepliesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Creates a new reply to a comment.
/// </summary>
public string CommentId { get; set; }
/// <summary>
/// Creates a new reply to a comment.
/// </summary>
public string FileId { get; set; }
}
/// <summary>
/// Creates a new reply to a comment.
/// </summary>
/// <param name="service"></param>
/// <param name="body"></param>
/// <param name="fileId">The ID of the file.</param>
/// <param name="commentId">The ID of the comment.</param>
/// <param name="options"></param>
/// <returns></returns>
public static Reply CreateReplies(DriveService service, Reply body, string fileId, string commentId, CreateRepliesOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
return service.Replies.Create(body, fileId, commentId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Replies.Create failed with message {ex.Message}", ex);
}
}
public class DeleteRepliesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Deletes a reply.
/// </summary>
public string CommentId { get; set; }
/// <summary>
/// Deletes a reply.
/// </summary>
public string FileId { get; set; }
/// <summary>
/// Deletes a reply.
/// </summary>
public string ReplyId { get; set; }
}
/// <summary>
/// Deletes a reply.
/// </summary>
/// <param name="service"></param>
/// <param name="fileId">The ID of the file.</param>
/// <param name="commentId">The ID of the comment.</param>
/// <param name="replyId">The ID of the reply.</param>
/// <param name="options"></param>
/// <returns></returns>
public static void DeleteReplies(DriveService service, string fileId, string commentId, string replyId, DeleteRepliesOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
service.Replies.Delete(fileId, commentId, replyId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Replies.Delete failed with message {ex.Message}", ex);
}
}
public class GetRepliesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Gets a reply by ID.
/// </summary>
public string CommentId { get; set; }
/// <summary>
/// Gets a reply by ID.
/// </summary>
public string FileId { get; set; }
/// <summary>
/// Gets a reply by ID.
/// </summary>
public bool IncludeDeleted { get; set; }
/// <summary>
/// Gets a reply by ID.
/// </summary>
public string ReplyId { get; set; }
}
/// <summary>
/// Gets a reply by ID.
/// </summary>
/// <param name="service"></param>
/// <param name="fileId">The ID of the file.</param>
/// <param name="commentId">The ID of the comment.</param>
/// <param name="replyId">The ID of the reply.</param>
/// <param name="options"></param>
/// <returns></returns>
public static Reply GetReplies(DriveService service, string fileId, string commentId, string replyId, GetRepliesOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
return service.Replies.Get(fileId, commentId, replyId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Replies.Get failed with message {ex.Message}", ex);
}
}
public class ListRepliesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Lists a comment's replies.
/// </summary>
public string CommentId { get; set; }
/// <summary>
/// Lists a comment's replies.
/// </summary>
public string FileId { get; set; }
/// <summary>
/// Lists a comment's replies.
/// </summary>
public bool IncludeDeleted { get; set; }
/// <summary>
/// Lists a comment's replies.
/// </summary>
public int PageSize { get; set; }
/// <summary>
/// Lists a comment's replies.
/// </summary>
public string PageToken { get; set; }
}
/// <summary>
/// Lists a comment's replies.
/// </summary>
/// <param name="service"></param>
/// <param name="fileId">The ID of the file.</param>
/// <param name="commentId">The ID of the comment.</param>
/// <param name="options"></param>
/// <returns></returns>
public static ReplyList ListReplies(DriveService service, string fileId, string commentId, ListRepliesOptionalParameters options)
{
// A page streamer is a helper to provide both synchronous and asynchronous page streaming
// of a listable or queryable resource.
var pageStreamer =
new PageStreamer<Reply, RepliesResource.ListRequest, ReplyList, string>(
(request, token) => request.PageToken = token,
response => response.NextPageToken, response => response.Replies);
try
{
var results = new ReplyList();
var request = service.Replies.List(fileId, commentId);
// iterate through the results
foreach (var result in pageStreamer.Fetch(request))
{
results.Replies.Add(result);
}
return results;
}
catch (Exception ex)
{
throw new Exception($"Request Replies.List failed with message {ex.Message}", ex);
}
}
public class UpdateRepliesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Updates a reply with patch semantics.
/// </summary>
public string CommentId { get; set; }
/// <summary>
/// Updates a reply with patch semantics.
/// </summary>
public string FileId { get; set; }
/// <summary>
/// Updates a reply with patch semantics.
/// </summary>
public string ReplyId { get; set; }
}
/// <summary>
/// Updates a reply with patch semantics.
/// </summary>
/// <param name="service"></param>
/// <param name="body"></param>
/// <param name="fileId">The ID of the file.</param>
/// <param name="commentId">The ID of the comment.</param>
/// <param name="replyId">The ID of the reply.</param>
/// <param name="options"></param>
/// <returns></returns>
public static Reply UpdateReplies(DriveService service, Reply body, string fileId, string commentId, string replyId, UpdateRepliesOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
return service.Replies.Update(body, fileId, commentId, replyId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Replies.Update failed with message {ex.Message}", ex);
}
}
}
}
using Google.Apis.Drive.v3;
using Google.Apis.Drive.v3.Data;
using System;
using Google.Apis.Requests;
namespace GoogleApiSample.Drivev3
{
public static class RevisionsExamples
{
public class DeleteRevisionsOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Permanently deletes a file version. You can only delete revisions for files with binary content in Google Drive, like images or videos. Revisions for other files, like Google Docs or Sheets, and the last remaining file version can't be deleted.
/// </summary>
public string FileId { get; set; }
/// <summary>
/// Permanently deletes a file version. You can only delete revisions for files with binary content in Google Drive, like images or videos. Revisions for other files, like Google Docs or Sheets, and the last remaining file version can't be deleted.
/// </summary>
public string RevisionId { get; set; }
}
/// <summary>
/// Permanently deletes a file version. You can only delete revisions for files with binary content in Google Drive, like images or videos. Revisions for other files, like Google Docs or Sheets, and the last remaining file version can't be deleted.
/// </summary>
/// <param name="service"></param>
/// <param name="fileId">The ID of the file.</param>
/// <param name="revisionId">The ID of the revision.</param>
/// <param name="options"></param>
/// <returns></returns>
public static void DeleteRevisions(DriveService service, string fileId, string revisionId, DeleteRevisionsOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
service.Revisions.Delete(fileId, revisionId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Revisions.Delete failed with message {ex.Message}", ex);
}
}
public class GetRevisionsOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Gets a revision's metadata or content by ID.
/// </summary>
public bool AcknowledgeAbuse { get; set; }
/// <summary>
/// Gets a revision's metadata or content by ID.
/// </summary>
public string FileId { get; set; }
/// <summary>
/// Gets a revision's metadata or content by ID.
/// </summary>
public string RevisionId { get; set; }
}
/// <summary>
/// Gets a revision's metadata or content by ID.
/// </summary>
/// <param name="service"></param>
/// <param name="fileId">The ID of the file.</param>
/// <param name="revisionId">The ID of the revision.</param>
/// <param name="options"></param>
/// <returns></returns>
public static Revision GetRevisions(DriveService service, string fileId, string revisionId, GetRevisionsOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
return service.Revisions.Get(fileId, revisionId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Revisions.Get failed with message {ex.Message}", ex);
}
}
public class ListRevisionsOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Lists a file's revisions.
/// </summary>
public string FileId { get; set; }
/// <summary>
/// Lists a file's revisions.
/// </summary>
public int PageSize { get; set; }
/// <summary>
/// Lists a file's revisions.
/// </summary>
public string PageToken { get; set; }
}
/// <summary>
/// Lists a file's revisions.
/// </summary>
/// <param name="service"></param>
/// <param name="fileId">The ID of the file.</param>
/// <param name="options"></param>
/// <returns></returns>
public static RevisionList ListRevisions(DriveService service, string fileId, ListRevisionsOptionalParameters options)
{
// A page streamer is a helper to provide both synchronous and asynchronous page streaming
// of a listable or queryable resource.
var pageStreamer =
new PageStreamer<Revision, RevisionsResource.ListRequest, RevisionList, string>(
(request, token) => request.PageToken = token,
response => response.NextPageToken, response => response.Revisions);
try
{
var results = new RevisionList();
var request = service.Revisions.List(fileId);
// iterate through the results
foreach (var result in pageStreamer.Fetch(request))
{
results.Revisions.Add(result);
}
return results;
}
catch (Exception ex)
{
throw new Exception($"Request Revisions.List failed with message {ex.Message}", ex);
}
}
public class UpdateRevisionsOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Updates a revision with patch semantics.
/// </summary>
public string FileId { get; set; }
/// <summary>
/// Updates a revision with patch semantics.
/// </summary>
public string RevisionId { get; set; }
}
/// <summary>
/// Updates a revision with patch semantics.
/// </summary>
/// <param name="service"></param>
/// <param name="body"></param>
/// <param name="fileId">The ID of the file.</param>
/// <param name="revisionId">The ID of the revision.</param>
/// <param name="options"></param>
/// <returns></returns>
public static Revision UpdateRevisions(DriveService service, Revision body, string fileId, string revisionId, UpdateRevisionsOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
return service.Revisions.Update(body, fileId, revisionId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Revisions.Update failed with message {ex.Message}", ex);
}
}
}
}
using Google.Apis.Drive.v3;
using Google.Apis.Drive.v3.Data;
using System;
using Google.Apis.Requests;
namespace GoogleApiSample.Drivev3
{
public static class TeamdrivesExamples
{
public class CreateTeamdrivesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Deprecated use drives.create instead.
/// </summary>
public string RequestId { get; set; }
}
/// <summary>
/// Deprecated use drives.create instead.
/// </summary>
/// <param name="service"></param>
/// <param name="body"></param>
/// <param name="requestId">An ID, such as a random UUID, which uniquely identifies this user's request for idempotent creation of a Team Drive. A repeated request by the same user and with the same request ID will avoid creating duplicates by attempting to create the same Team Drive. If the Team Drive already exists a 409 error will be returned.</param>
/// <param name="options"></param>
/// <returns></returns>
public static TeamDrive CreateTeamdrives(DriveService service, TeamDrive body, string requestId, CreateTeamdrivesOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
return service.Teamdrives.Create(body, requestId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Teamdrives.Create failed with message {ex.Message}", ex);
}
}
public class DeleteTeamdrivesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Deprecated use drives.delete instead.
/// </summary>
public string TeamDriveId { get; set; }
}
/// <summary>
/// Deprecated use drives.delete instead.
/// </summary>
/// <param name="service"></param>
/// <param name="teamDriveId">The ID of the Team Drive</param>
/// <param name="options"></param>
/// <returns></returns>
public static void DeleteTeamdrives(DriveService service, string teamDriveId, DeleteTeamdrivesOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
service.Teamdrives.Delete(teamDriveId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Teamdrives.Delete failed with message {ex.Message}", ex);
}
}
public class GetTeamdrivesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Deprecated use drives.get instead.
/// </summary>
public string TeamDriveId { get; set; }
/// <summary>
/// Deprecated use drives.get instead.
/// </summary>
public bool UseDomainAdminAccess { get; set; }
}
/// <summary>
/// Deprecated use drives.get instead.
/// </summary>
/// <param name="service"></param>
/// <param name="teamDriveId">The ID of the Team Drive</param>
/// <param name="options"></param>
/// <returns></returns>
public static TeamDrive GetTeamdrives(DriveService service, string teamDriveId, GetTeamdrivesOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
return service.Teamdrives.Get(teamDriveId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Teamdrives.Get failed with message {ex.Message}", ex);
}
}
public class ListTeamdrivesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Deprecated use drives.list instead.
/// </summary>
public int PageSize { get; set; }
/// <summary>
/// Deprecated use drives.list instead.
/// </summary>
public string PageToken { get; set; }
/// <summary>
/// Deprecated use drives.list instead.
/// </summary>
public string Q { get; set; }
/// <summary>
/// Deprecated use drives.list instead.
/// </summary>
public bool UseDomainAdminAccess { get; set; }
}
/// <summary>
/// Deprecated use drives.list instead.
/// </summary>
/// <param name="service"></param>
/// <param name="options"></param>
/// <returns></returns>
public static TeamDriveList ListTeamdrives(DriveService service, ListTeamdrivesOptionalParameters options)
{
// A page streamer is a helper to provide both synchronous and asynchronous page streaming
// of a listable or queryable resource.
var pageStreamer =
new PageStreamer<TeamDrive, TeamdrivesResource.ListRequest, TeamDriveList, string>(
(request, token) => request.PageToken = token,
response => response.NextPageToken, response => response.Teamdrives);
try
{
var results = new TeamDriveList();
var request = service.Teamdrives.List();
// iterate through the results
foreach (var result in pageStreamer.Fetch(request))
{
results.Teamdrives.Add(result);
}
return results;
}
catch (Exception ex)
{
throw new Exception($"Request Teamdrives.List failed with message {ex.Message}", ex);
}
}
public class UpdateTeamdrivesOptionalParameters
{
/// <summary>
/// Selector specifying which fields to include in a partial response.
/// </summary>
public string Fields { get; set; }
/// <summary>
/// An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
/// </summary>
public string QuotaUser { get; set; }
/// <summary>
/// Deprecated use drives.update instead
/// </summary>
public string TeamDriveId { get; set; }
/// <summary>
/// Deprecated use drives.update instead
/// </summary>
public bool UseDomainAdminAccess { get; set; }
}
/// <summary>
/// Deprecated use drives.update instead
/// </summary>
/// <param name="service"></param>
/// <param name="body"></param>
/// <param name="teamDriveId">The ID of the Team Drive</param>
/// <param name="options"></param>
/// <returns></returns>
public static TeamDrive UpdateTeamdrives(DriveService service, TeamDrive body, string teamDriveId, UpdateTeamdrivesOptionalParameters options)
{
try
{
// Initial validation.
if (service == null)
throw new ArgumentNullException(nameof(service));
// Make the request.
return service.Teamdrives.Update(body, teamDriveId).Execute();
}
catch (Exception ex)
{
throw new Exception($"Request Teamdrives.Update failed with message {ex.Message}", ex);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment