static string[] Scopes = { SheetsService.Scope.Spreadsheets };
static string ApplicationName = "Google Sheets API .NET Quickstart";
public String spreadsheetId;
SheetsService service;
public GoogleHandler(String id)
{
spreadsheetId = id;
UserCredential credential;
using (var stream =
new FileStream(@"bin\client_secret.json", FileMode.Open, FileAccess.Read))
{
string credPath = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.Personal);
credPath = Path.Combine(credPath, ".credentials/sheets.googleapis.com-dotnet-quickstart.json");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
}
service = new SheetsService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
}
This is my code for Google Sheets API. I have the static string[] Scopes = { SheetsService.Scope.Spreadsheets };
which were solutions I found for this problem, however that did not fix my problem. I have already deleted my .credentials folder and it does not prompt me to login.
I commented out that line and it fixed everything!