Click here to Skip to main content
15,510,087 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to dynamically export data to google sheets but i got this error

Google.Apis.Requests.RequestErrorFile not found: . [404]Errors [	Message[File not found: .] Location[fileId - parameter] Reason[notFound] Domain[global]]


What I have tried:

public Google.Apis.Drive.v3.Data.File CreateSheet()  
{  
      string[] scopes = new string[] { DriveService.Scope.Drive,  
                      DriveService.Scope.DriveFile,};  
     var clientId = "123456337-wajklowlksflmxiowerasjdflsl.apps.googleusercontent.com";      // From https://console.developers.google.com  
     var clientSecret = "kkslfdkiwowol_ssdwerss";          // From https://console.developers.google.com  
     // here is where we Request the user to give us access, or use the Refresh Token that was previously stored in %AppData%  
     var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets  
     {  
         ClientId = clientId,  
         ClientSecret = clientSecret  
     },scopes,  
     Environment.UserName,CancellationToken.None,new FileDataStore("MyAppsToken")).Result;  
     //Once consent is recieved, your token will be stored locally on the AppData directory, so that next time you wont be prompted for consent.   
     DriveService _service = new DriveService(new BaseClientService.Initializer()  
     {  
         HttpClientInitializer = credential,  
         ApplicationName = "MyAppName",  
  
     });  
    var _parent = "";//ID of folder if you want to create spreadsheet in specific folder
    var filename = "helloworld";
    var fileMetadata = new Google.Apis.Drive.v3.Data.File()  
    {  
        Name = filename,  
        MimeType = "application/vnd.google-apps.spreadsheet",  
        //TeamDriveId = teamDriveID, // IF you want to add to specific team drive  
    };  
    FilesResource.CreateRequest request = _service.Files.Create(fileMetadata);  
    request.SupportsTeamDrives = true;  
    fileMetadata.Parents = new List<string> { _parent }; // Parent folder id or TeamDriveID  
    request.Fields = "id";  
    System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };  
    var file = request.Execute();  
    MessageBox.Show("File ID: " + file.Id);  
    return file;  
}  
Posted
Comments
ZurdoDev 31-Jan-20 7:25am    
404 means it's the wrong url so I'd refer to the documentation.
Richard Deeming 31-Jan-20 8:18am    
I hope that's not your real clientSecret that you've just published on a public forum?

You know, the one you're supposed to keep secret?

If it is, you'd better revoke and regenerate your API keys immediately.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900