来自 Objective C 的 WordPress XML-RPC 调用:wp.newComment
我正在使用 Eric Czarny 的 Cocoa XML-RPC 框架来调用 Wordpress API。我已经从 Wordpress 下载了示例应用程序,其中提供了一些很好的示例。不幸的是,除了 wp.newComment 之外,每个调用都有很好的例子。
我正在尝试使用下面的代码发表评论,但我不断收到一个带有本地化描述的错误,告诉我检查我的输入参数。我检查了又检查,但我不明白出了什么问题。
有什么想法吗?
NSDictionary *commentStructure = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:0], @"comment_parent", @"xmlrpc anonymous comments plugin now enabled", @"content", @"Test Author", @"author", @"http://iphone.someurl.com", @"author_url", @"[email protected]", @"author_email", nil];
NSArray *args = [NSArray arrayWithObjects:[NSNumber numberWithInt:0], @"", @"", [NSNumber numberWithInt:[self.parentFeedItem.postID intValue]], commentStructure, nil]; // the param(s)
NSString *server = [[[NSString alloc] initWithString:@"http://www.someurl.com/xmlrpc.php"] autorelease]; // the server
NSString *method = [[[NSString alloc] initWithString:@"wp.newComment"] autorelease]; // the method
XMLRPCRequest *request = [[XMLRPCRequest alloc] initWithHost:[NSURL URLWithString:server]];
[request setMethod:method withObjects:args];
id response = [self executeXMLRPCRequest:request];
[request release];
if( [response isKindOfClass:[NSError class]] ) {
//return nil;
NSLog(@"There was a problem");
NSLog([response localizedDescription]);
}
I'm using Eric Czarny's Cocoa XML-RPC framework to make a call to the Wordpress API's. I've downloaded the sample app from Wordpress which gives some good examples. Unfortunately the good examples are for every call EXCEPT wp.newComment.
I'm trying to post a comment using the code below and I keep getting an error with a localized description that tells me to check my input parameters. I've checked and rechecked and I don't understand what is wrong.
Any ideas?
NSDictionary *commentStructure = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:0], @"comment_parent", @"xmlrpc anonymous comments plugin now enabled", @"content", @"Test Author", @"author", @"http://iphone.someurl.com", @"author_url", @"[email protected]", @"author_email", nil];
NSArray *args = [NSArray arrayWithObjects:[NSNumber numberWithInt:0], @"", @"", [NSNumber numberWithInt:[self.parentFeedItem.postID intValue]], commentStructure, nil]; // the param(s)
NSString *server = [[[NSString alloc] initWithString:@"http://www.someurl.com/xmlrpc.php"] autorelease]; // the server
NSString *method = [[[NSString alloc] initWithString:@"wp.newComment"] autorelease]; // the method
XMLRPCRequest *request = [[XMLRPCRequest alloc] initWithHost:[NSURL URLWithString:server]];
[request setMethod:method withObjects:args];
id response = [self executeXMLRPCRequest:request];
[request release];
if( [response isKindOfClass:[NSError class]] ) {
//return nil;
NSLog(@"There was a problem");
NSLog([response localizedDescription]);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现我下载了旧版本的示例 Wordpress 源代码,其中没有 wp.newComment 的示例。
您可以在这里找到源代码的更新版本,其中确实有更好的示例。
http://iphone.trac.wordpress.org/browser
使用较新代码中的示例我能够解决我的问题。
I found that I had downloaded an older version of the example Wordpress source code which did not have an example for wp.newComment.
You can find a much newer version of the source code here which does have better examples.
http://iphone.trac.wordpress.org/browser
Using the examples from the newer code I was able to resolve my issues.