Created
March 18, 2016 14:29
-
-
Save DannySotzny/0ce64cebf39e9e420187 to your computer and use it in GitHub Desktop.
Init GDRIVE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void InitService() | |
{ | |
UserCredential credential; | |
using (var stream = | |
new FileStream("client_id.json", FileMode.Open, FileAccess.Read)) | |
{ | |
string credPath = Environment.GetFolderPath( | |
Environment.SpecialFolder.Personal); | |
credPath = Path.Combine(credPath, ".credentials/drive-dotnet-quickstart.json"); | |
credential = GoogleWebAuthorizationBroker.AuthorizeAsync( | |
GoogleClientSecrets.Load(stream).Secrets, | |
Scopes, | |
"user", | |
CancellationToken.None, | |
new FileDataStore(credPath, true)).Result; | |
_log.Debug("Credential file saved to: " + credPath); | |
} | |
// Create Drive API service. | |
_service = new DriveService(new BaseClientService.Initializer() | |
{ | |
HttpClientInitializer = credential, | |
ApplicationName = ApplicationName, | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment