我目前有一个XML文件需要发送给Google来更新我的工作表/电子表格中的单元格。我已经用库编写了XML,我希望它的格式正确为Google's Spreadsheet API。
在this教程之后,我收到的消息说“无法更新小区的位置”。我不确定我做错了哪一部分,但是我在Objective-C中实现了对API的调用:
-(void) callAPI:(NSString *)apiURL withHttpMethod:(HTTPMethod)method XMLString:(NSString *) xml
{
NSString *urlString = [NSString stringWithFormat:@"%@?access_token=%@", apiURL, _accessTokenInfoDictionary[@"access_token"]];
NSLog(@"URLString: %@", urlString);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]
initWithURL:[NSURL
URLWithString:urlString]];
if (method == PUT) {
[request setHTTPMethod:@"PUT"];
[request setValue:@"application/atom+xml" forHTTPHeaderField:@"Content-Type"];
[request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[xml length]] forHTTPHeaderField:@"Content-length"];
[request setHTTPBody:[xml dataUsingEncoding:NSUTF8StringEncoding]];
[self makeRequest:request];
}
}
我在this的帮助下使用OAuth 2,但它不处理xml文件,因此我必须为其实现一个方法。
应用程序编写的XML文件如下所示:
<?xml version="1.0" encoding="UTF-8" ?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gs="http://schemas.google.com/spreadsheets/2006">
<id>https://spreadsheets.google.com/feeds/cells/theworksheetid/od6/private/full/R3C1</id>
<link rel="edit" type="application/atom+xml" href="https://spreadsheets.google.com/feeds/cells/theworksheetid/od6/private/full/R3C1/15d60i" />
<gs:cell row="2" col="4" inputValue="Testing with XML Writer!!" />
</entry>
方法callAPI
生成的访问令牌如下所示:
https://spreadsheets.google.com/feeds/cells/theworksheetid/od6/private/full/R3C1/15d60i?access_token=some_access_token
所以,我不确定这是否是我实现方法的方式,或者是XML文件或访问令牌不允许我更新单元格,但任何帮助都可以,谢谢。
答案 0 :(得分:1)
问题解决了。问题是创建的XML文件中的行和列与给我的单元格条目中的行和列不匹配。所以我所要做的就是匹配它们,发送XML和tada,现在我能够编辑单元格了!