我试图做一个批量更新与谷歌表API的iOS,但我得到一个错误无效的值在'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);
}
}];
My Request参数是
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), "纬度"data[0]处的值无效。values[3]' (type.googleapis.com/google.protobuf.ListValue), "经度"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"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]处的无效值。values[0]' (type.googleapis.com/google.protobuf.ListValue), "客户ID"data[0]处的值无效。values[1]' (type.googleapis.com/google.protobuf.ListValue), "客户名称"data[0]处的值无效。values[2]' (type.googleapis.com/google.protobuf.ListValue), "纬度"data[0]处的值无效。values[3]' (type.googleapis.com/google.protobuf.ListValue), "经度"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"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", nslocalizedfailurerreason =(data[0]处无效值。values[0]' (type.googleapis.com/google.protobuf.ListValue), "客户ID"data[0]处的值无效。values[1]' (type.googleapis.com/google.protobuf.ListValue), "客户名称"data[0]处的值无效。values[2]' (type.googleapis.com/google.protobuf.ListValue), "纬度"data[0]处的值无效。values[3]' (type.googleapis.com/google.protobuf.ListValue), "经度"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"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 'data[0]. "values[0]' (type.googleapis.com/google.protobuf.ListValue), "客户ID"data[0]处的值无效。values[1]' (type.googleapis.com/google.protobuf.ListValue), "客户名称"data[0]处的值无效。values[2]' (type.googleapis.com/google.protobuf.ListValue), "纬度"data[0]处的值无效。values[3]' (type.googleapis.com/google.protobuf.ListValue), "经度"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"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" errors? ":[1]状态?:"INVALID_ARGUMENT"}}
value是一个2d数组。它们应该是[['a', 'b', 'c'], [1,2,3]]
你提供的值作为一个1d数组['a', 'b', 'c'],错误信息是抱怨'a'不能适合一个ListValue,因为它不是一个数组。解决方案是使用2d数组,尽管我不能在这里提供一个例子,你应该做什么,因为我不确定你打算如何将你的输入映射到电子表格。
我没有足够的点来评论Sam Berlin的帖子,但我一直在努力找出为什么我不能添加一行到谷歌表,事实证明,我使用的是字符串,而不是所需的二维数组:https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values#ValueRange(我开始怀疑它是否是一个谷歌认证的东西或我使用Ionic/Angular/google sheets系统的其他一些领域https://github.com/doughazell/ionic-camera-swipe)
错误表明请求参数有一个无效的值,错误响应提供了关于哪个值无效的信息。在未解决问题之前不要重试。您需要为错误响应中指定的参数提供一个有效值。您需要对API查询进行更改才能使其工作。您的Customer Name, Latitude, Longitude
值无效。检查你的错误日志
这是一个表单API BatchUpdate博客遇到400错误响应:https://github.com/google/google-api-nodejs-client/issues/588