我正在尝试将数据发布到google散页,但得到404错误,验证了我的工作表id,所有的一切看起来都很好,但仍然有404错误,下面是我的代码。
NSString *baseUrl = @"https://sheets.googleapis.com/v4/spreadsheets/";
NSString *spreadsheetId = @"MYKEY/edit";
NSString *range = @"Sheet1!A2:E";
baseUrl= [baseUrl stringByAppendingString:spreadsheetId];
baseUrl = [baseUrl stringByAppendingString:@"/values/"];
baseUrl = [baseUrl stringByAppendingString:range];
NSMutableDictionary * params=[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"RAW",@"valueInputOption", nil];
NSURL *postURL=[GTLUtilities URLWithString:baseUrl queryParameters:params];
NSLog(@"base url is %@", postURL);
GTLObject * body=[[GTLObject alloc]init];
NSMutableArray * contentArray=[[NSMutableArray alloc]init];
NSMutableArray * titleArray=[[NSMutableArray alloc]initWithObjects:@"Student Name",@"Gender",@"Class Level",@"Home State",@"Major",@"Extracurricular Activity",nil];
NSMutableArray * wheelArray=[[NSMutableArray alloc]initWithObjects:@"TEST",@"TEST",@"50.00",@"100.00",@"2",@"2", nil];
[contentArray addObjectsFromArray:titleArray];
[contentArray addObjectsFromArray:wheelArray];
NSLog(@"content array is %@", contentArray);
NSMutableDictionary * bodyDict=[[NSMutableDictionary alloc]initWithObjectsAndKeys:range,@"range",@"ROWS",@"majorDimension",@"HELLO",@"values", nil];
NSLog(@"body dict %@",bodyDict);
body.JSON=[[NSMutableDictionary alloc]initWithObjectsAndKeys:@"range",range,@"majorDimension",@"ROWS",@"values",@"HELLO", nil];
[self.service fetchObjectByUpdatingObject:body forURL:[NSURL URLWithString:baseUrl] completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error) {
if (error==nil) {
NSLog(@"posted content successfully");
}
}];发布于 2016-08-11 10:05:27
删除/edit in you spreadsheetId
在范围中的E列后添加一个数字
发布于 2016-08-11 11:43:08
根据您的后续评论,在修复问题后,其他人指出,您现在失败了,范围不足。为了告诉服务器用户授予了应用程序权限,您需要代表用户请求OAuth授权。通过创建一个auth控制器,iOS QuickStart解释了如何做到这一点:
`// Creates the auth controller for authorizing access to Google Sheets API. - (GTMOAuth2ViewControllerTouch *)createAuthController { GTMOAuth2ViewControllerTouch *authController; // If modifying these scopes, delete your previously saved credentials by // resetting the iOS simulator or uninstall the app. NSArray *scopes = [NSArray arrayWithObjects:@"https://www.googleapis.com/auth/spreadsheets", nil]; authController = [[GTMOAuth2ViewControllerTouch alloc] initWithScope:[scopes componentsJoinedByString:@" "] clientID:kClientID clientSecret:nil keychainItemName:kKeychainItemName delegate:self finishedSelector:@selector(viewController:finishedWithAuth:error:)]; return authController; }` ( quickstart使用spreadsheets.readonly作用域,但我在上面将其更改为spreadsheets,因为它看起来像是要修改数据。)
您需要确保正确地调用createAuthController方法(并且只在必要时),并且在它完成授权时也会正常运行。快速启动指南详细解释了这一点。
https://stackoverflow.com/questions/38892743
复制相似问题