# Configure Google Drive Web API Service

## Content



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

1.  [Configure Storage Connection String](/componentone/docs/webapi/online-webapi/Services/cloudservices/configuregoogledriveservice#step-1-configure-storage-connection-string)
2.  [Register the Cloud Service](/componentone/docs/webapi/online-webapi/Services/cloudservices/configuregoogledriveservice#step-2-register-the-cloud-service)
3.  [Perform Operations](/componentone/docs/webapi/online-webapi/Services/cloudservices/configuregoogledriveservice#step-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](https://developers.google.com/drive/api/v3/enable-sdk).

### 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
    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; 
            }
    ```
    
    <br />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
    using Google.Apis.Drive.v3; 
       string[] scopes = { DriveService.Scope.Drive }; 
       string applicationName = "yout application name"; 
       app.UseStorageProviders().AddGoogleDriveStorage("GoogleDrive", GetUserCredential(scopes), applicationName);
    ```

### 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](/componentone/docs/webapi/online-webapi/Services/cloudservices/performoperations).