I'm writing an app that needs to record data in a Google Spreadsheet with Swift
.
I'm just really uncertain how to actually get started! I set up the Google sheets API
in the Google API
console and in my cocoapods following the Quickstart provided by google. Google's libraries GoogleAPIClientForREST
and GTMOAuth2
are in my app and are ready to be used.
I basically just need to read and write to an existing spreadsheet but I do not know how to create the spreadsheet and refer to it so I can read and write to it as needed.
Thanks!
Whenever I want to read or write to a Google spreadsheet using the Sheets API, I refer to Reading & Writing Cell Values.
Basic Reading
The following spreadsheets.values.get request reads the values stored in the range Sheet1!A1:D5 and returns them in the response. Empty trailing rows and columns are omitted.
GET https://sheets.googleapis.com/v4/spreadsheets/spreadsheetId/values/Sheet1!A1:D5
Basic Writing
Starting with a new, blank spreadsheet, the following spreadsheets.values.update request will write the values to the range Sheet1!A1:D5. The ValueInputOption query parameter is required and determines if the values written will be parsed (for example, whether or not a string is converted into a date).
PUT https://sheets.googleapis.com/v4/spreadsheets/spreadsheetId/values/Sheet1!A1:D5?valueInputOption=USER_ENTERED
Here's the iOS Swift Quickstart for your code reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With