Skip to content

Commit

Permalink
- Added extra help when Google Drive does not initialize correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
KoalaBear84 committed Jun 7, 2020
1 parent 6850bf9 commit 239f7b1
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions OpenDirectoryDownloader.GoogleDrive/GoogleDriveIndexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,38 @@ public static class GoogleDriveIndexer

static GoogleDriveIndexer()
{
UserCredential credential;

using (FileStream fileStream = new FileStream("OpenDirectoryDownloader.GoogleDrive.json", FileMode.Open, FileAccess.Read))
try
{
// The file token.json stores the user's access and refresh tokens, and is created
// automatically when the authorization flow completes for the first time.
string credPath = "token.json";
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(fileStream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;

Console.WriteLine($"Credential file saved to: {credPath}");
}
UserCredential credential;

// Create Drive API service.
DriveService = new DriveService(new BaseClientService.Initializer()
using (FileStream fileStream = new FileStream("OpenDirectoryDownloader.GoogleDrive.json", FileMode.Open, FileAccess.Read))
{
// The file token.json stores the user's access and refresh tokens, and is created
// automatically when the authorization flow completes for the first time.
string credPath = "token.json";
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(fileStream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;

Console.WriteLine($"Credential file saved to: {credPath}");
}

// Create Drive API service.
DriveService = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
}
catch (Exception ex)
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
Console.WriteLine($"Error initializing Google Drive, please check OpenDirectoryDownloader.GoogleDrive.json and/or remove the 'token.json' directory. See readme on Github for more help. ERROR: {ex}");
Logger.Error(ex, "Error initializing Google Drive, please check OpenDirectoryDownloader.GoogleDrive.json and/or remove the 'token.json' directory. See readme on Github for more help.");
throw;
}
}

public static async Task<WebDirectory> IndexAsync(WebDirectory webDirectory)
Expand Down

0 comments on commit 239f7b1

Please sign in to comment.