1

I want to develop an asp.net/c# web application where users of my application can upload files. The files will be stored in a common Google drive. I know the log-in id and password of that drive(actually that’s my Drive).

Authenticating process will be done in background. Users don’t know where the files been stored and they need no Google drive permission so no need of consent screen.

Is it possible by Google-drive-sdk ? Or any suggestion how can I develop the app ?

Thanks !

pinoyyid
  • 21,499
  • 14
  • 64
  • 115
hasnayn
  • 356
  • 4
  • 22

2 Answers2

0

What you are talking about is called a Service account. Think of a service account as a user, you don't have a log-in and password for it but it does have a drive account. You also cant log into it using the website version of drive. Everything has to go though the API.

string[] scopes = 
          new string[] { DriveService.Scope.Drive,
                         DriveService.Scope.DriveFile};    

string keyFilePath = @"c:\file.p12" ;    // found in developer console
string serviceAccountEmail = "xx@developer.gserviceaccount.com";  // found in developer console
//loading the Key file
var certificate = new X509Certificate2(keyFilePath, "notasecret", X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential( new ServiceAccountCredential.Initializer(serviceAccountEmail)
                                                                  {
                                                                   Scopes = scopes    
                                                             }.FromCertificate(certificate));

Creating the service:

DriveService service = new DriveService(new BaseClientService.Initializer()
 {
 HttpClientInitializer = credential,
 ApplicationName = "Drive API Sample",
 });

All requests will then be run though the service. I have a tutorial that will walk you though that and there is a sample project on GitHub to go along with it. Google Drive API with C# Note: the tutorial uses oauth2 use the above authentication code to authenticate with a Service Account.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
0

You can use a Service Account as described by @DaImTo

You can also use your own account (your question says "actually that’s my Drive") as described here How do I authorise an app (web or installed) without user intervention? (canonical ?)

Community
  • 1
  • 1
pinoyyid
  • 21,499
  • 14
  • 64
  • 115
  • thanks for answer. how can i get UserCredential for getting drive service using refresh token in c# ? any example or link .. – hasnayn Nov 25 '14 at 06:34
  • sorry I don't use the c# libraries. I'm sure there will be a form of constructor that allows you to wrap an existing token. The library doesn't care how the refresh token was generated, since it is normally stored in a database for later retrieval. You'll then use the refresh token to generate an access token. I guess UserCredential is basically a wrapper for an access token – pinoyyid Nov 25 '14 at 09:07