In the following tutorial, we’ll be reading a Google Sheet (https://docs.google.com/spreadsheets/d/1-6XeX59-zgqi_z5Bm8dqYyO1z37tfi8Ur7o5mxmmVKo/edit?usp=sharing), porting it into an ASP.NET web site.
- Create a new Visual Studio ASP.NET C# project (Ctrl + Shift + N)
- Create a new empty web site
- Create a new master page, naming it site.master, and a new content page, default.aspx
- Visit https://developers.google.com/sheets/api/quickstart/dotnet and enable the Google Sheets API
- Go to https://console.developers.google.com/projectcreate, give your project a name, note your project id, and click Next.
- Now go to your project: https://console.developers.google.com/apis/library?project=projectid
- Enable the Google Sheets API
- Visit https://console.developers.google.com/apis/api/sheets.googleapis.com/credentials?project=projectid and click Configure Consent Screen
- Click External and click Next
- Give you app a name, home page, authorized domain, and add yourself as a test user
- Click Add or Remove Scopes
- Check the box for See, edit, create, and delete your spreadsheets in Google Drive and View your Google Spreadsheets
- Click Save and Continue
- Click Go Back to Dashboard
- Click Credentials and click Create OAuth client ID
- Click Web Application, add a name, and add your authorized JavaScript origins and redirect URIs, including http://localhost/authorize/ and http://127.0.0.1/authorize/
- Copy your client id
- Copy your client secret
- Download your OAuth 2.0 Client Id json file
- Save the file
credentials.json
to your working directory. - Open the NuGet Package Manager Console, and run the following command:
Install-Package Google.Apis.Sheets.v4
- Add a new ASP.NET folder –> App_Code to your solution
- Create a new class in the solution named GoogleSheets.cs