Google Sheet API批量更新问题iOS

我尝试使用Google表格API进行批量更新,但在“data [0] .values [0]”(type.googleapis.com/google.protobuf.ListValue)上收到错误无效值,

这是我的代码

NSString *baseUrl = @"https://sheets.googleapis.com/v4/spreadsheets/"; NSString *spreadsheetId = @"1tJd4toWFxmHAEOeONauRPcuH_rWJOESLQT7TvCIK0x0"; baseUrl= [baseUrl stringByAppendingString:spreadsheetId]; baseUrl = [baseUrl stringByAppendingString:@"/values:batchUpdate/"]; NSMutableDictionary * params=[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"USER_ENTERED",@"valueInputOption", nil]; NSURL *postURL=[GTLUtilities URLWithString:baseUrl queryParameters:params]; NSLog(@"base url is %@", postURL); GTLObject * body=[[GTLObject alloc]init]; NSMutableArray * titleArray=[[NSMutableArray alloc]initWithObjects:@"Customer ID",@"Customer Name",@"Latitude",@"Longitude" ,@"Last_Updated_At",nil]; NSMutableArray * wheelArray2=[[NSMutableArray alloc]initWithObjects:@"rt",@"SHJ",@"150.00",@"100.00",@"2:00:00", nil]; //[contentArray addObject:titleArray]; NSMutableDictionary * batchParams=[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"USER_ENTERED",@"valueInputOption", nil]; NSMutableArray * batchParametersContentArray=[[NSMutableArray alloc]init]; NSMutableDictionary* batchParametersTitlesDict=[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Sheet1!A1:E1",@"range",@"COLUMNS",@"majorDimension",titleArray,@"values", nil]; NSMutableDictionary* batchParametersContentDict=[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Sheet1!A7:E7",@"range",@"ROWS",@"majorDimension",wheelArray2,@"values", nil]; [batchParametersContentArray addObject:batchParametersTitlesDict]; [batchParametersContentArray addObject:batchParametersContentDict]; [batchParams setObject:batchParametersContentArray forKey:@"data"]; NSLog(@"batch params are %@",batchParams); body.JSON=batchParams; [self.service fetchObjectByInsertingObject:body forURL:postURL completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error) { if (error==nil) { NSLog(@"batch performed successfully"); } else { NSLog(@"error is %@", error); } }]; 

我的请求参数是

 batch params are { data = ( { majorDimension = COLUMNS; range = "Sheet1!A1:E1"; values = ( "Customer ID", "Customer Name", Latitude, Longitude, "Last_Updated_At" ); }, { majorDimension = ROWS; range = "Sheet1!A7:E7"; values = ( rt, SHJ, "150.00", "100.00", "2:00:00" ); } ); valueInputOption = "USER_ENTERED"; } 

错误是

 error is Error Domain=com.google.GTLJSONRPCErrorDomain Code=400 "(Invalid value at 'data[0].values[0]' (type.googleapis.com/google.protobuf.ListValue), "Customer ID" 

“data [0] .values [1]”(type.googleapis.com/google.protobuf.ListValue),“客户名称”在“data [0] .values [2]”处的值无效(type.googleapis .com / google.protobuf.ListValue)“Latitude”“data [0] .values [3]”(type.googleapis.com/google.protobuf.ListValue)上的值无效,“Longitude” 0] .values [4]“(type.googleapis.com/google.protobuf.ListValue),”Last_Updated_At“在”data [1] .values [0]“(type.googleapis.com/google.protobuf)上的值无效。 “数据[1] .values [1]”(type.googleapis.com/google.protobuf.ListValue),“SHJ”上的无效值“data [1] .values [2] (type.googleapis.com/google.protobuf.ListValue),“150.00”“data [1] .values [3]”(type.googleapis.com/google.protobuf.ListValue),“100.00”的值无效值为'data [1] .values [4]'(type.googleapis.com/google.protobuf.ListValue),“2:00:00”)“UserInfo = {error ='data'的值无效[0]。值[0]“(type.googleapis.com/google.protobuf.ListValue),”客户ID“无效的值 在'data [0] .values [1]'(type.googleapis.com/google.protobuf.ListValue),“Customer Name”在'data [0] .values [2]'(type.googleapis。 com / google.protobuf.ListValue),“Latitude”在“data [0] .values [3]”(type.googleapis.com/google.protobuf.ListValue)上的值无效,“Longitude”在“data [0] ] .values [4]“(type.googleapis.com/google.protobuf.ListValue),”Last_Updated_At“”data [1] .values [0]“处的值无效(type.googleapis.com/google.protobuf.ListValue )“rt”“data [1] .values [1]”(type.googleapis.com/google.protobuf.ListValue)上的值无效,“SHJ”数据[1] .values [2]中的值无效(type.googleapis.com/google.protobuf.ListValue),“150.00”“data [1] .values [3]”(type.googleapis.com/google.protobuf.ListValue),“100.00”的值无效在'data [1] .values [4]'(type.googleapis.com/google.protobuf.ListValue),“2:00:00”,NSLocalizedFailureReason =(数据[0] .values [0] (type.googleapis.com/google.protobuf.ListValue),“客户ID”无效值a t'data [0] .values [1]'(type.googleapis.com/google.protobuf.ListValue),“Customer Name”data'[0] .values [2]'中的值无效(type.googleapis.com /google.protobuf.ListValue)“Latitude”“data [0] .values [3]”(type.googleapis.com/google.protobuf.ListValue)上的值无效,“Longitude” .values [4]“(type.googleapis.com/google.protobuf.ListValue),”Last_Updated_At“data'[1] .values [0]'(type.googleapis.com/google.protobuf.ListValue) ,“rt”在“data [1] .values [1]”(type.googleapis.com/google.protobuf.ListValue)上的值无效,“SHJ”在data [1] .values [2]上的值无效type.googleapis.com/google.protobuf.ListValue),“150.00”“data [1] .values [3]”(type.googleapis.com/google.protobuf.ListValue)上的值无效,“100.00” 'data [1] .values [4]'(type.googleapis.com/google.protobuf.ListValue),“2:00:00”),GTLStructuredError = GTLErrorObject 0x7f89ca465990:{code:400 message:“Invalid value at'数据[0] .values [0]“(type.googleapis.com/google.protobuf。 “数据[0] .values [1]”(type.googleapis.com/google.protobuf.ListValue)上的“客户ID”无效值,“数据[0] .values [ 2]“(type.googleapis.com/google.protobuf.ListValue),”Latitude“的值为”data [0] .values [3]“(type.googleapis.com/google.protobuf.ListValue),”Longitude “data [0] .values [4]”(type.googleapis.com/google.protobuf.ListValue),“Last_Updated_At”上的值无效“data [1] .values [0]”(type.googleapis .com / google.protobuf.ListValue),“rt”“data [1] .values [1]”(type.googleapis.com/google.protobuf.ListValue)上的值无效,“SHJ” 1] .values [2]“(type.googleapis.com/google.protobuf.ListValue),”150.00“”data [1] .values [3]“(type.googleapis.com/google.protobuf)上的值无效。 ListValue),“100.00”“data [1] .values [4]”(type.googleapis.com/google.protobuf.ListValue),“2:00:00”“errors?:[1] status? :“无效的论点”}}

值旨在是一个二维数组。 它们应该是[['a','b','c'],[1,2,3]]的forms

你提供的值是一个1d数组['a','b','c'],错误信息是抱怨'a'不能放入ListValue中,因为它不是数组。 解决的办法是使用2d数组,虽然我不能在这里提供一个例子,你应该做什么,因为我不知道你打算如何将你的input映射到电子表格。

该错误指示请求参数具有无效值,并且错误响应提供关于哪个值无效的信息。 不要在没有解决问题的情况下重试。 您需要为错误响应中指定的参数提供有效的值。 您需要对API查询进行更改才能运行。 您的Customer Name, Latitude, Longitude值无效。 检查你的错误日志。

以下是一个Sheets API BatchUpdate博客遇到的400错误响应: https : //github.com/google/google-api-nodejs-client/issues/588