To configure Google Drive Web API Service and perform different operations, follow these steps:
Create Google API and get the credentials.json
file to your project. For more information on Google Drive API, see Configure your UI integration.
Code |
Copy Code
|
---|---|
using Google.Apis.Auth.OAuth2; private UserCredential GetUserCredential(string[] scopes) { UserCredential credential; using (var fileStream = new FileStream(HttpContext.Current.Server.MapPath("credentials.json"), FileMode.Open, FileAccess.Read)) { string credPath = "token.json"; credential = GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(fileStream).Secrets, scopes, "user", CancellationToken.None, new FileDataStore(HttpContext.Current.Server.MapPath(credPath), true)).Result; } return credential; } |
Code |
Copy Code
|
---|---|
using Google.Apis.Drive.v3; string[] scopes = { DriveService.Scope.Drive }; string applicationName = "yout application name"; app.UseStorageProviders().AddGoogleDriveStorage("GoogleDrive", GetUserCredential(scopes), applicationName); |
You can choose to perform various operations, such as listing data, uploading, deleting or downloading a file, after registering the cloud service. To understand how to perform these operations, see Perform Operations.
Back to Top