gpt4 book ai didi

ios - 如何通过 Google Sheets API 进行基本写作?

转载 作者:行者123 更新时间:2023-11-29 00:53:55 24 4
gpt4 key购买 nike

在使用 Swift 学习 Google Sheets API 的过程中,我想将单个范围写入电子表格。

调查Quickstart iOS GuideBasic Writing examples我带来了这段代码:

func constructAndSendAQuery() {
let baseUrl = "https://sheets.googleapis.com/v4/spreadsheets"
let spreadsheetId = "1FhbBdEvpcyHsdfgsdft65eDGHre2fLVki5ZolMmZaRs"
let range = "Sales!A31:C31"
let url = baseUrl + "/" + spreadsheetId + "/values/" + range
let params = ["valueInputOption": "RAW"]
let fullUrl = GTLUtilities.URLWithString(url, queryParameters: params)

let body = GTLObject()
body.JSON = ["majorDimension":"ROWS",
"values": ["One", "Two", "Three"]]

service.fetchObjectByInsertingObject(body,
forURL: fullUrl,
delegate: self,
didFinishSelector: #selector(ViewController.processTheResponse(_:finishedWithObject:error:)))
}

不知道我做错了什么,但我收到错误消息:“在此服务器上找不到请求的 URL”。

最佳答案

正如 @sam-berlin 提到的,我应该使用 fetchObjectByUpdatingObject 而不是 fetchObjectByInsertUpdating

但是还有一个小错误/打字错误。在构建 JSON 时,我丢失了一对方括号并收到有关无效值的错误。

工作代码如下所示:

func constructAndSendARequest() {

let baseUrl = "https://sheets.googleapis.com/v4/spreadsheets"
let spreadsheetId = "1FhbBdEvpsfgzb3Akn1opmru0iresdfglbki5ZMmZaRs"
let range = "Sales!A3:D3"
let url = baseUrl + "/" + spreadsheetId + "/values/" + range
let params = ["valueInputOption": "RAW"]
let fullUrl = GTLUtilities.URLWithString(url, queryParameters: params)


let body = GTLObject()
body.JSON = ["range": range,
"majorDimension": "ROWS",
"values": [["One", "Two", "Three"]]]

service.fetchObjectByUpdatingObject(body, forURL: fullUrl, delegate: self, didFinishSelector: #selector(ViewController.processTheResponse(_:finishedWithObject:error:)))
}

也可以使用 service.fetchObjectByUpdatingObject(body, forURL: fullUrl,completionHandler: nil) 而不处理响应。

关于ios - 如何通过 Google Sheets API 进行基本写作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37810535/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com