Web API Edition | ComponentOne
Services / Cloud Services / Configure Google Drive Web API Service
In This Topic
    Configure Google Drive Web API Service
    In This Topic

    To configure Google Drive Web API Service and perform different operations, follow these steps:

    1. Configure Storage Connection String
    2. Register the Cloud Service
    3. Perform Operations

    Step 1: Configure Storage Connection String

    Create Google API and get the credentials.json file to your project. For more information on Google Drive API, see Configure your UI integration.

    Back to Top

    Step 2: Register the Cloud Service

    1. Create a new C1 Web API Application and make sure the following references are added to the application:
      • C1.Web.Api.dll
      • C1.Web.Api.Cloud.dll
    2. Add the "credentials.json" credential file to the project.
    3. Install Google.Apis.Drive.v3 NuGet package from the NuGet Package Manager.
    4. Create a method, say GetUserCredential, to get the credentials from credentials.json file using the following code:
      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; 
              }
      

      Note that the file token.json stores the user's access and refreshes tokens, and is created automatically when the authorization flow completes for the first time.
    5. Register the Google Drive cloud service using the following code:
      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);
      
    Back to Top

    Step 3: Perform Operations

    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