11

I'm using .net package Google.Apis.Sheets.v4 Client Library. Everything was fine, but last time (about a week ago) there is an error: The request is missing a valid API key. [403] when I'm trying to batchGet with 150+ ranges in a query. If I split my query to 25 ranges in a single query, it could be ok, also it could return the same error at one of them. Sometimes it works without any splitting, but usually I get an error. I'm absolutely sure that my API key is valid and I've tried another keys, another spreadsheets, but nothing has changed.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
lagrange-
  • 215
  • 1
  • 2
  • 9
  • I started using service key instead of api key and problem had gone. Init SheetsService with option `HttpClientInitializer = GoogleCredential.FromJson("")` – lagrange- Sep 23 '20 at 13:53

2 Answers2

3

Some of the answers in this SO post have point to handle this 403 error.

First thing, make sure that you have permission to call the specific spreadsheet and enable the Sheets API in your developer console. Another thing, try to change the privacy settings of this spreadsheet to public and checked if you can access it now. You will usually get 403 error when you have missed or incorrect configuration in Authorizing Requests. Make sure to use proper scope if you are authorizing requests with OAuth 2.0

MαπμQμαπkγVπ.0
  • 5,887
  • 1
  • 27
  • 65
  • For authorization of my requests I'm using API key and app name. It's very strange, because it works more than year and if spreadsheet was closed, I've got a specific error. But there is problem with API key. – lagrange- May 30 '18 at 10:30
  • I've noticed that `Get` request never gets such error but `batchGet` fails. – lagrange- May 30 '18 at 10:34
2

Check this conversation.

Instead of google.sheets({version: 'v4', oAuth2Client})

use google.sheets({version: 'v4', auth: oAuth2Client})

Pragalathan M
  • 1,673
  • 1
  • 14
  • 19