I'm starting to study Google Drive's Api for a personal project in .NET, and I followed the step-by-step guide available on the google website
But when I was running the code at the time of obtaining the credentials happened this error:
Hereisthecodeused:
usingGoogle.Apis.Auth.OAuth2;usingGoogle.Apis.Drive.v3;usingGoogle.Apis.Services;usingGoogle.Apis.Util.Store;usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Threading;namespaceTestesGoogleDrive{classProgram{//Ifmodifyingthesescopes,deleteyourpreviouslysavedcredentials//at~/.credentials/drive-dotnet-quickstart.jsonstaticstring[]Scopes={DriveService.Scope.Drive};staticstringApplicationName="Drive API .NET Quickstart";
static void Main(string[] args)
{
UserCredential credential;
using (var stream =
new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
{
string credPath = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.Personal);
// credPath = Path.Combine(credPath, "credentials/drive-dotnet-quickstart.json");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
Console.WriteLine("Credential file saved to: " + credPath);
}
// Create Drive API service.
var service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
// Define parameters of request.
FilesResource.ListRequest listRequest = service.Files.List();
listRequest.PageSize = 10;
listRequest.Fields = "nextPageToken, files(id, name)";
// List files.
IList<Google.Apis.Drive.v3.Data.File> files = listRequest.Execute()
.Files;
Console.WriteLine("Files:");
if (files != null && files.Count > 0)
{
foreach (var file in files)
{
Console.WriteLine("{0} ({1})", file.Name, file.Id);
}
}
else
{
Console.WriteLine("No files found.");
}
Console.Read();
}
}
}
Packages installed in the project as it is in the tutorial, plus settings in the client_secret.json file to always copy to the output as it is also in the tutorial:
Has this problem ever happened to anyone or anything like it?