Member 13909869 Ответов: 0

Я пытаюсь экспортировать свои данные сетки в Google sheet in ASP.NET с#


Я пытаюсь динамически экспортировать данные в google sheets, но у меня есть эта ошибка

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


Что я уже пробовал:

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;  
}  

ZurdoDev

404 означает, что это неправильный url-адрес, поэтому я бы обратился к документации.

Richard Deeming

Надеюсь, это не твоя вина. реальный" clientSecret что вы только что опубликовали на публичном форуме?

Ну, знаешь, тот, который ты должен был оставить себе секрет?

Если это так, то вам лучше отозвать и регенерировать свои ключи API немедленно.

0 Ответов