2

I have been tasked with pulling data from Google Sheets and storing the information in a database. I have reviewed the documentation and I am a bit confused about having to create a cloud platform project. The sheets that I am attempting to read do not have any user authentication, anybody has access to them.

1
  • 1
    The fact that the sheets are public doesn't mean you can access them via API, I think you need to have a credential. Commented Jun 11, 2019 at 18:59

1 Answer 1

2

If it's a public sheet then you can use a public API key to access it. Google needs to know who is using their API. They do that by requiring that you create a project on google developer console and create keys to access even public data.

namespace GoogleSamplecSharpSample.Sheetsv4.Auth
{
    /// <summary>
    /// When calling APIs that do not access private user data, you can use simple API keys. These keys are used to authenticate your 
    /// application for accounting purposes. The Google API Console documentation also describes API keys.
    /// https://support.google.com/cloud/answer/6158857
    /// </summary>
    public static class ApiKeyExample
    {
        /// <summary>
        /// Get a valid SheetsService for a public API Key.
        /// </summary>
        /// <param name="apiKey">API key from Google Developer console</param>
        /// <returns>SheetsService</returns>
        public static SheetsService GetService(string apiKey)
        {
            try
            {
                if (string.IsNullOrEmpty(apiKey))
                    throw new ArgumentNullException("api Key");

                return new SheetsService(new BaseClientService.Initializer()
                {
                    ApiKey = apiKey,
                    ApplicationName = string.Format("{0} API key example", System.Diagnostics.Process.GetCurrentProcess().ProcessName),
                });
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to create new Sheets Service", ex);
            }
        }
    }
}

code ripped from APIKey.cs

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.