Skip to content

Instantly share code, notes, and snippets.

@DannySotzny
Created March 18, 2016 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DannySotzny/0ce64cebf39e9e420187 to your computer and use it in GitHub Desktop.
Save DannySotzny/0ce64cebf39e9e420187 to your computer and use it in GitHub Desktop.
Init GDRIVE
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