How do I access the Google Spreadsheets API in PHP?

南笙酒味 提交于 2019-11-28 09:44:08

You can use the PHP Google Spreadsheet Client library.

You'll need to use the Google APIs Client Library for PHP as well to authenticate via OAuth2. Developer documentation is linked on the github page.

Thanks for the hints and links on this page, I wanted to share what I ended up doing to read a google spreadsheet in php. You can access the spreadsheet in json format, and don't need to use api or zend framework or gdata library. PhP can handle json very easily and it was the most neat solution I could reach to because it has no dependency to any third party libraries.

Here is a sample link for getting a spreadsheet in json format.

https://spreadsheets.google.com/feeds/list/key/1/public/full?alt=json

Please note if spreadsheet is private you still need to follow the authentication steps to get token to access to the page. In my case the spreadsheet was public.

Also you can access the spreadsheet via feed list or cell based (replace the list in the url with cell)

You can try the link in a browser and see the json result.

wescpy

(Aug 2016)

As of this past May, you now have a better solution...

No more passing the buck:

  1. GData APIs (and thus Zend GData) are the previous generation of Google APIs. While not all GData APIs have been deprecated, all newer Google APIs do not use the Google Data protocol.
  2. There is a "new" Google Sheets API v4 (not GData]). In order to use the new Sheets API, you need to get the Google APIs Client Library for PHP as others have already stated. The latest API is much more powerful and flexible than any previous API. Here's one code sample to help get you started. If you're not "allergic" to Python, I also made a video with a different, slightly longer example introducing the API and gave a deeper dive into its code via a blogpost that you can learn from.

Note the Sheets API allows you to create spreadsheets & sheets, upload & download data, as well as, in the general sense, programmatically access a Sheet as if you were using the user interface (create frozen rows, perform cell formatting, resizing rows/columns, adding pivot tables, creating charts, etc.), but to perform file-level access such as uploads & downloads, imports & exports (same as uploads & downloads but conversion to/from Google Apps formats), you would use the Google Drive API instead.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!