Skip to content

Instantly share code, notes, and snippets.

@LindaLawton
Created July 22, 2015 07:15
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 LindaLawton/7b2280735406ed5df07b to your computer and use it in GitHub Desktop.
Save LindaLawton/7b2280735406ed5df07b to your computer and use it in GitHub Desktop.
OAuth2 Authentication to google Drive with C#
//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;
@b42sonu
Copy link

b42sonu commented Dec 13, 2016

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 :

  1. Given permission to folder (that store the outh response ). Like asp.net users .
  2. Tried with both folder default roaming folder and custom folder (for store the outh response)

Let me know if you want more information from my side.

Best regards,
Sunil Sharma

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment