title: Google Sheets API v4 Basics
body: <p>I am trying to get data from google sheets. For example, let's say I have a sheet "test" and I want to get cell a2 from "test", and so I save the contents of cell a2 as a string.</p>
  
  <p>I believe Google Sheets Api v4 (<a href="https://developers.google.com/api-client-library/dotnet/apis/sheets/v4" rel="nofollow noreferrer">https://developers.google.com/api-client-library/dotnet/apis/sheets/v4</a>) is what I need to use, but I am not sure how to use it. </p>
  
  <p>I have also found similar question posts on stack overflow, but they all seem outdated.</p>
  
  <p>Finally, I have tried this tutorial (<a href="https://developers.google.com/sheets/api/quickstart/dotnet#step_2_prepare_the_project" rel="nofollow noreferrer">https://developers.google.com/sheets/api/quickstart/dotnet#step_2_prepare_the_project</a>) with my c# visual studio, but I get error messages (which I can include if it is helpful).</p>
  
  <p>So, <strong>my question</strong> is, how do extract data from a google sheet, using the API or some other tool. Thanks for the help, and please notify me if my question needs editing to better fit this community.</p>
  
  <p><strong>edit</strong>: So, following the tutorial, I have this code:</p>
  
  <pre><code>using System;
  using System.Windows.Forms;
  using Google.Apis.Auth.OAuth2;
  using Google.Apis.Sheets.v4;
  using Google.Apis.Sheets.v4.Data;
  using Google.Apis.Services;
  using Google.Apis.Util.Store;
  
  using System.Collections.Generic;
  using System.IO;
  using System.Linq;
  using System.Text;
  using System.Threading;
  using System.Threading.Tasks;
  
  namespace GoogleSheetsTest1
  
  {
      public partial class Form1 : Form
      {
  
          public Form1()
          {
              InitializeComponent();
  
          }
  
          private void Form1_Load(object sender, EventArgs e)
          {
  
          }
          class Program
          {
              static string[] Scopes = { SheetsService.Scope.SpreadsheetsReadonly };
              static string ApplicationName = "Google Sheets API .NET Quickstart";
  
              static void Main(string[] args)
              {
                  UserCredential credential;
  
                  using (var stream =
                      new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
                  {
                      string credPath = System.Environment.GetFolderPath(
                          System.Environment.SpecialFolder.Personal);
                      credPath = Path.Combine(credPath, ".credentials/sheets.googleapis.com-dotnet-quickstart.json");
  
                      credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                          GoogleClientSecrets.Load(stream).Secrets,
                          Scopes,
                          "user",
                          CancellationToken.None,
                          new FileDataStore(credPath, true)).Result;
                      Console.WriteLine("Credential file saved to: " + credPath);
                  }
  
                  // Create Google Sheets API service.
                  var service = new SheetsService(new BaseClientService.Initializer()
                  {
                      HttpClientInitializer = credential,
                      ApplicationName = ApplicationName,
                  });
  
                  // Define request parameters.
                  String spreadsheetId = "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms";
                  String range = "Class Data!A2:E";
                  SpreadsheetsResource.ValuesResource.GetRequest request =
                          service.Spreadsheets.Values.Get(spreadsheetId, range);
  
                  // Prints the names and majors of students in a sample spreadsheet:
                  // https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/edit
                  ValueRange response = request.Execute();
                  IList&lt;IList&lt;Object&gt;&gt; values = response.Values;
                  if (values != null &amp;&amp; values.Count &gt; 0)
                  {
                      Console.WriteLine("Name, Major");
                      foreach (var row in values)
                      {
                          // Print columns A and E, which correspond to indices 0 and 4.
                          Console.WriteLine("{0}, {1}", row[0], row[4]);
                      }
                  }
                  else
                  {
                      Console.WriteLine("No data found.");
                  }
                  Console.Read();
  
  
              }
  
          }
      }
      }
  </code></pre>
  
  <p>The error message I am getting is:
  <em>Error  CS0017  Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point.</em>   </p>
  
  <p>I realize this is probably a really stupid question and I hate to be asking for help here, but I am not sure how to use the google api code, so any help/explanation (so I can understand what the fix is) would be really appreciated. Thanks</p>