Home > OS >  Accessing a public google sheet's data directly from client-side JavaScript
Accessing a public google sheet's data directly from client-side JavaScript

Time:01-29

Is there a way to get cell values of a public google spread sheet ?

GET https://sheets.googleapis.com/v4/spreadsheets/1vW01Y46DcpCC7aKLIUwV_W4RXLbeukVwF-G9AA7P7R0/values/A1A4?key=abcdef

returns 403.

I also sent the Referrer in Postman : Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36

{
    "error": {
        "code": 403,
        "message": "Requests from referer Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36 are blocked.",
        "status": "PERMISSION_DENIED",
        "details": [
            {
                "@type": "type.googleapis.com/google.rpc.ErrorInfo",
                "reason": "API_KEY_HTTP_REFERRER_BLOCKED",
                "domain": "googleapis.com",
                "metadata": {
                    "consumer": "projects/666",
                    "service": "sheets.googleapis.com"
                }
            }
        ]
    }
}

I am trying to access a public sheet's data directly from client-side JavaScript.

No round-trips to the server. I remember this was possible some 10 years ago but am unable to locate the docs.

CodePudding user response:

Based on Answer is to remove the restrictions in Google Cloud Console

CodePudding user response:

You can access the public spreadsheet by json endpoint

var id = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
var gid = '1111111111111';
var url = 'https://docs.google.com/spreadsheets/d/' id '/gviz/tq?tqx=out:json&tq&gid=' gid;

Take a slice and parse the json

The sheet ID you have provided is wrong.

  •  Tags:  
  • Related