Click here to Skip to main content
15,887,392 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, having some issues regarding google drive authentication on google drive, json file in root folder. any help will be deeply appreciated.

What I have tried:

C#
  1  using System;
  2  using Google.Apis.Auth.OAuth2;
  3  using Google.Apis.Drive.v3;
  4  using Google.Apis.Services;
  5  using System.Collections.Generic;
  6  using System.IO;
  7  using System.IO.MemoryMappedFiles;
  8  using System.Linq;
  9  using System.Text;
 10  using System.Threading;
 11  using System.Threading.Tasks;
 12  
 13  namespace ConsoleApp1
 14  {
 15      internal class Program
 16      {
 17          static async Task Main(string[] args)
 18          {;
 19                      var credentials =await GoogleCredential.FromFileAsync("mobileprice-389203-2c49de2ddaba.json");
 20              var service = new DriveService(new BaseClientService.Initializer());
 21          Console.WriteLine(credentials);
 22          }
 23      }
 24  }
CS7036
There is no argument given that corresponds to the required parameter 'cancellationToken' of 'GoogleCredential.FromFileAsync(string, CancellationToken)'
Program.cs, Line 19
Posted
Updated 8-Jun-23 1:08am
v2

Quote:
CS7036 There is no argument given that corresponds to the required parameter 'cancellationToken' of 'GoogleCredential.FromFileAsync(string, CancellationToken)'
The FromFileAsync method requires two arguments. You are only passing one.

If you don't have a CancellationToken to pass, then pass CancellationToken.None:
C#
var credentials = await GoogleCredential.FromFileAsync("mobileprice-389203-2c49de2ddaba.json", CancellationToken.None);
 
Share this answer
 
Comments
suhail malik 2023 8-Jun-23 7:28am    
thanks iwas giving cancelationtoken onle. and i have to put json file in bin /debug folder
Richard Deeming 8-Jun-23 7:30am    
Yes it does:
CancellationToken.None Property (System.Threading) | Microsoft Learn[^]

Available since CancellationToken was added in .NET Framework 4.0.
suhail malik 2023 8-Jun-23 7:35am    
Severity Code Description Project File Line Suppression State
Error CS0103 The name 'cancellationToken' does not exist in the current context ConsoleApp1 D:\maui\ConsoleApp1\ConsoleApp1\Program.cs 19 Active
Richard Deeming 8-Jun-23 7:45am    
C# is case senstive. There is a significant difference between cancellationToken and CancellationToken.
The error message is clear, you are missing a required parameter on the call to GoogleCredential.FromFileAsync. It has nothing to do with the location of the file, since your code will not even compile.
 
Share this answer
 
First off, that file isn't in the "root folder" - it's in the "current folder" which will be the one the app EXE file is running from.

That may be causing your problem, but since you don't provide any info on what the problem might be reporting as we can't tell.

And if the file is in the root folder then that could be a problem all of it's own: depending on how the code attempts to open the file, that may fail as the root of some drives are write protected for security reasons.

See here: Where should I store my data?[^] for some better ideas.
 
Share this answer
 
Comments
suhail malik 2023 8-Jun-23 7:01am    
yes, json file is in current folder. should i place it some where else ane how can i retrieve the file. there is nothing much more regarding my question. i created google drive api key and trying to run the file for the first time.
OriginalGriff 8-Jun-23 7:10am    
"Current folder" is generally a mistake as it tends to fail in production when the app is installed under the "Program Files" folder as that is also write protected for security.
You should use the appropriate data folder as suggested in the article I linked to.

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