2

I have the greatest trouble finding information about what I need. I guess I'm not looking in the right places since this is quite basic. Anyway.

Somebody somewhere has created a Google Sheet anyone with the link can access. I want to retrieve the value of a given cell.

I'd like to be able to do the following in JS from a simple web page (or server side in PHP, but preferably JS):

AGoogleApiIHopeExists.setApiKey("<MY_API_KEY");
var value = AGoogleApiIHopeExists
    .getSheet("AJEIDNNS6886SDHSKN67HBS7BA6SD555DSHD")
    .getTab("MyTabInsideMySheet")
    .getCell("B:17");

I'm afraid I'm a bit naive to think this is possible...

If not, where should I look for more info?

JstnPwll
  • 8,585
  • 2
  • 33
  • 56
Silverspur
  • 891
  • 1
  • 12
  • 33

1 Answers1

6

Try reading through the Google Sheets API. It is a REST API you can use to access & edit Google sheets. You do not need their client libraries (Java, .NET, etc.)

If the sheet is private, you will need to use OAuth 2.0 to gain access through a user account.

If the sheet is public, you will be able to access it without login. Note though that the sheet must still be published before you can access it.

I did some digging to help you out. Try this endpoint:

https://spreadsheets.google.com/feeds/cells/<sheetID>/default/public/full/R1C1?alt=json

R1C1 refers to Row 1, Column 1. You can change this as needed. default refers to the worksheet (tab) ID. If you need a different worksheet than the default, there are other API endpoints you can use to fetch the appropriate worksheet ID.

Here is a simple jsfiddle which allows you to enter a few variables and see the resulting value.

JstnPwll
  • 8,585
  • 2
  • 33
  • 56
  • 1
    It's a REST API, you aren't required to use their client libraries. See my updated answer. – JstnPwll Nov 05 '15 at 17:06
  • @Silverspur, was this what you needed? – JstnPwll Nov 11 '15 at 18:23
  • I did not have time to look in details your answer (thus having not accepted it yet), but it seems to be what I'm looking for. However, the constraint of having to publish the sheets before being able to access them is kind of a deal breaker for me here. – Silverspur Nov 12 '15 at 23:27
  • 1
    Yep, that constraint is kind of obnoxious. The only alternative is to use the private feeds (with OAuth). – JstnPwll Nov 13 '15 at 14:27