1

I'm trying to upload a small sample CSV file up to my personal google drive via a Service Account, but it keeps failing.

I've created a folder in my personal Drive, and shared it with my Service Account (Editor role), so it seems like this should work.

Here is my code (VB.net running on .Net framework 4.8)

    Sub Main()

        '--1.  Instantiate service with service account creditentials
        Dim credential As GoogleCredential
        Dim myScopes As String() = {DriveService.ScopeConstants.Drive}

        Using fs As New FileStream("credentials2.json", FileMode.Open, FileAccess.Read)
            credential = GoogleCredential.FromStream(fs).CreateScoped(myScopes)
        End Using

        Dim uploadService As DriveService = New DriveService(New BaseClientService.Initializer() With {
                .HttpClientInitializer = credential, .ApplicationName = "Google Drive test"})

        '--2.  Set up the destination file metadata.  I'm using a folder from My Drive
        Dim parentList As New List(Of String)
        parentList.Add("FolderIdFromMyDrive")

        Dim googleFileMetadata As New Google.Apis.Drive.v3.Data.File()

        googleFileMetadata.Name = "Test File 1"
        googleFileMetadata.Parents = parentList
        'googleFileMetadata.MimeType = "application/vnd.google-apps.spreadsheet"
        googleFileMetadata.MimeType = "text/csv"

        '--3.  Upload csv file to a folder in My Drive
        Dim csvFile As String = "C:\Test\TestFile1.csv"
        Dim uploadRequest As FilesResource.CreateMediaUpload
        Dim uploadResponse As IUploadProgress

        Using csvStream As New FileStream(csvFile, FileMode.Open, FileAccess.Read)
            uploadRequest = uploadService.Files.Create(googleFileMetadata, csvStream, "text/csv")
            uploadResponse = uploadRequest.Upload()
        End Using

        If uploadResponse IsNot Nothing Then
            Console.WriteLine(uploadResponse.Exception.Message)
        End If

        Console.ReadKey()
    End Sub

When I run this, I'll get different errors for different MIME types. If I set the MimeType to "text/csv" I get this

HttpStatusCode is Forbidden. Service Accounts do not have storage quota. Leverage shared drives (https://developers.google.com/workspace/drive/api/guides/about-shareddrives), or use OAuth delegation (http://support.google.com/a/answer/7281227) instead.

If I change the MimeType to "application/vnd.google-apps.spreadsheet" I get this

HttpStatusCode is Forbidden. The user's Drive storage quota has been exceeded

The issue appears to be with the Service Account. Is there something I have to configure on the Service Account to make this work?

Edit (8/1/2025) So the error I'm getting (Service Accounts do not have storage quota) is just that. I called About.Get() on the DriveService, and my StorageQuota.Limit is 0. All the sample code I've tried never mentions this.

This post reports similar behavior. My alternatives is to authenicate via OAuth Client ID's or delegation, and so far I'm finding this to be quite challenging.

4
  • How much free storage do you have in your drive? Commented Aug 1 at 1:59
  • I've only used about 300kb out of 15gb. I've read somewhere that it's actually writing it to the Service Account drive, even though I specifically asked to write it to my shared folder. Commented Aug 1 at 12:29
  • What other things have you tried? Just so you know, features like Domain-Wide Delegation and Shared Drives, are features exclusive to Google Workspace accounts and cannot be used with a personal @gmail.com account. Commented Aug 4 at 14:25
  • @LimeHusky I'm trying to develop a feature to upload files to a Google Drive for another customer. Right now I don't have access to a valid Google Workspace, so for testing purposes, I've been trying to upload to my personal Drive in the meantime. Every attempt I've made to create a file using a Service Account has failed with a 'Storage Quota' issue. I'm close to getting this to work an OAuth Client ID, but it's been difficult. Commented Aug 4 at 18:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.