OAuth2 Authentication to google Drive with C#
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
//Scopes for use with the Google Drive API | |
string[] scopes = new string[] { DriveService.Scope.Drive, | |
DriveService.Scope.DriveFile}; | |
var clientId = "[Client ID]"; // From https://console.developers.google.com | |
var clientSecret = "xxx"; // From https://console.developers.google.com | |
// here is where we Request the user to give us access, or use the Refresh Token that was previously stored in %AppData% | |
var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = clientId, | |
ClientSecret = clientSecret}, | |
scopes, | |
Environment.UserName, | |
CancellationToken.None, | |
new FileDataStore("Daimto.GoogleDrive.Auth.Store")).Result; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I am working on C# MVC web application . In this application I am integrating google drive and using Google.Apis (version- 1.19.0.0). For this implementation I have taken the reference from your sample code and have implemented successfully in my application. During testing I have found that it is working fine when I run directly this from visual studio but when I deployed this on IIS (even local IIS) it is not working. After investigation I have found that it is giving problem in authentication and not trigger the authenticate screen with Gmail account. Mainly giving me on this below line :
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets {ClientId = clientId, ClientSecret = clientSecret} , scopes , userName , CancellationToken.None
, new FileDataStore(folder,true)).Result;
Nothing has happened after this line (no error) . Kindly help me on this . How I can solve this problem? Is there any setting in IIS that I need to set for this ?
Some trouble shooting I already done like :
Let me know if you want more information from my side.
Best regards,
Sunil Sharma