Google Sheet API批量更新问题iOS [英] Google Sheet API batch update issue iOS

查看:256
本文介绍了Google Sheet API批量更新问题iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用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];


$ b NSMutableArray * titleArray = [[NSMutableArray alloc] initWithObjects:@Customer ID,@Customer Name,@Latitude,@Longitude,@ Last_Updated_At,零]。
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,@ 价值观,无];


NSMutableDictionary * batchParametersContentDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@Sheet1!A7:E7,@range,@ROWS,@majorDimension,wheelArray2,@ 价值观,无];


[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(@批量执行成功);
}
else
{
NSLog(@error is%@,error);
}

}];

我的请求参数是

 批量参数为{
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 数据[0] .values [1]中的值无效,客户ID

'(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.protobu f.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。 客户名称
'data [0] .values [2]'(type.googleapis.com/google.protobuf.ListValue),Latitude
的值无效值'数据[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
Inv中的值无效'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,NSLocalizedFailureReason =(数据[0] .values [0]无效值(type.googleapis.com/google.protobuf.ListValue),客户ID
数据上的值无效[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
da处的值无效(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: '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)上的值无效, 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
'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:00errors?:[1] status?:INVALID_ARGUMENT}}

解决方案

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

你'将数值作为1d数组['a','b','c']提供,并且错误消息抱怨'a'不适合ListValue,因为它不是数组。解决方案是使用2d数组,尽管我不能在这里提供一个例子来说明你应该做什么,因为我不知道你打算如何将你的输入映射到电子表格。


Am trying to do a batch update with google sheet API for iOS but am getting an error invalid value at 'data[0].values[0]' (type.googleapis.com/google.protobuf.ListValue),

here is my code

 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 parameters are

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";
}

The error is

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

Invalid value at 'data[0].values[1]' (type.googleapis.com/google.protobuf.ListValue), "Customer Name" Invalid value at 'data[0].values[2]' (type.googleapis.com/google.protobuf.ListValue), "Latitude" Invalid value at 'data[0].values[3]' (type.googleapis.com/google.protobuf.ListValue), "Longitude" Invalid value at 'data[0].values[4]' (type.googleapis.com/google.protobuf.ListValue), "Last_Updated_At" Invalid value at 'data[1].values[0]' (type.googleapis.com/google.protobuf.ListValue), "rt" Invalid value at 'data[1].values[1]' (type.googleapis.com/google.protobuf.ListValue), "SHJ" Invalid value at 'data[1].values[2]' (type.googleapis.com/google.protobuf.ListValue), "150.00" Invalid value at 'data[1].values[3]' (type.googleapis.com/google.protobuf.ListValue), "100.00" Invalid value at 'data[1].values[4]' (type.googleapis.com/google.protobuf.ListValue), "2:00:00")" UserInfo={error=Invalid value at 'data[0].values[0]' (type.googleapis.com/google.protobuf.ListValue), "Customer ID" Invalid value at 'data[0].values[1]' (type.googleapis.com/google.protobuf.ListValue), "Customer Name" Invalid value at 'data[0].values[2]' (type.googleapis.com/google.protobuf.ListValue), "Latitude" Invalid value at 'data[0].values[3]' (type.googleapis.com/google.protobuf.ListValue), "Longitude" Invalid value at 'data[0].values[4]' (type.googleapis.com/google.protobuf.ListValue), "Last_Updated_At" Invalid value at 'data[1].values[0]' (type.googleapis.com/google.protobuf.ListValue), "rt" Invalid value at 'data[1].values[1]' (type.googleapis.com/google.protobuf.ListValue), "SHJ" Invalid value at 'data[1].values[2]' (type.googleapis.com/google.protobuf.ListValue), "150.00" Invalid value at 'data[1].values[3]' (type.googleapis.com/google.protobuf.ListValue), "100.00" Invalid value at 'data[1].values[4]' (type.googleapis.com/google.protobuf.ListValue), "2:00:00", NSLocalizedFailureReason=(Invalid value at 'data[0].values[0]' (type.googleapis.com/google.protobuf.ListValue), "Customer ID" Invalid value at 'data[0].values[1]' (type.googleapis.com/google.protobuf.ListValue), "Customer Name" Invalid value at 'data[0].values[2]' (type.googleapis.com/google.protobuf.ListValue), "Latitude" Invalid value at 'data[0].values[3]' (type.googleapis.com/google.protobuf.ListValue), "Longitude" Invalid value at 'data[0].values[4]' (type.googleapis.com/google.protobuf.ListValue), "Last_Updated_At" Invalid value at 'data[1].values[0]' (type.googleapis.com/google.protobuf.ListValue), "rt" Invalid value at 'data[1].values[1]' (type.googleapis.com/google.protobuf.ListValue), "SHJ" Invalid value at 'data[1].values[2]' (type.googleapis.com/google.protobuf.ListValue), "150.00" Invalid value at 'data[1].values[3]' (type.googleapis.com/google.protobuf.ListValue), "100.00" Invalid value at '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), "Customer ID" Invalid value at 'data[0].values[1]' (type.googleapis.com/google.protobuf.ListValue), "Customer Name" Invalid value at 'data[0].values[2]' (type.googleapis.com/google.protobuf.ListValue), "Latitude" Invalid value at 'data[0].values[3]' (type.googleapis.com/google.protobuf.ListValue), "Longitude" Invalid value at 'data[0].values[4]' (type.googleapis.com/google.protobuf.ListValue), "Last_Updated_At" Invalid value at 'data[1].values[0]' (type.googleapis.com/google.protobuf.ListValue), "rt" Invalid value at 'data[1].values[1]' (type.googleapis.com/google.protobuf.ListValue), "SHJ" Invalid value at 'data[1].values[2]' (type.googleapis.com/google.protobuf.ListValue), "150.00" Invalid value at 'data[1].values[3]' (type.googleapis.com/google.protobuf.ListValue), "100.00" Invalid value at 'data[1].values[4]' (type.googleapis.com/google.protobuf.ListValue), "2:00:00"" errors?:[1] status?:"INVALID_ARGUMENT"}}

解决方案

Values are intended to be a 2d array. They should be in the form of [[ 'a', 'b', 'c'], [ 1, 2, 3 ]]

You're supplying the values as a 1d array ['a', 'b', 'c'], and the error message is complaining the 'a' can't fit into a ListValue since it's not an array. The solution is to use a 2d array, although I can't provide an example here of exactly what you should do since I'm not sure how you intend your input to map to the spreadsheet.

这篇关于Google Sheet API批量更新问题iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆