Please help. It's my first time working with Google libraries, and I'm trying to run at least one example, but it's not working.
My goal is to upload and download a file from Google Drive. For my first test, I'm trying it on my own Google account.
I took samples from https://github.com/googleworkspace/dotnet-samples, downloaded the gcloud CLI, and ran 'gcloud auth application-default login' to log in to my Google account.
After that, the initialization started working in the samples:
GoogleCredential credential = GoogleCredential.GetApplicationDefault().CreateScoped(DriveService.Scope.Drive);
But now, when I try to upload a test file using the function below, it gives me an error:
protected string CreateTestBlob(string filePath)
{
var fileMetadata = new Google.Apis.Drive.v3.Data.File();
fileMetadata.Name = "photo.jpg";
using (var stream = new FileStream(filePath, FileMode.Open))
{
var request = service.Files.Create(
fileMetadata, stream, "image/jpeg");
request.Fields = "id";
IUploadProgress test = request.Upload();
var file = request.ResponseBody;
return "";
}
}
The line IUploadProgress test = request.Upload(); returns an exception: "The service drive has thrown an exception. HttpStatusCode is Forbidden. Request had insufficient authentication scopes."
What does it require from me, and how can I upload a file from my computer to my Google Drive using their client libraries?