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.
@gmail.comaccount.