我真的很head头。我正在使用Pocket API允许用户从我的应用中归档Pocket文章,但是每当尝试使用以下代码进行归档时,都会出现此错误:
错误域= PocketSDK代码= 400“无效的请求,请参阅API文档” UserInfo = 0xc17d3b0 {NSLocalizedDescription =无效的请求,请参阅API文档}
码:
NSDictionary *arguments = @{@"action": @"archive",
@"item_id": articleID};
[[PocketAPI sharedAPI] callAPIMethod:@"send" withHTTPMethod:PocketAPIHTTPMethodPOST arguments:arguments handler:^(PocketAPI *api, NSString *apiMethod, NSDictionary *response, NSError *error) {
if (!error) {
NSLog(@"Archived article.");
}
}];
究竟哪一部分是不正确的?我不将发送方法发布到API吗?
编辑:我什至将其更改为
@"action"
为@"actions"
并提供给上面的NSDictionary,它返回时没有错误,但在Pocket网站上不受影响。编辑2:根据Joseph Chen的回复,我将代码更改为以下内容:
// Create data to pass to the Pocket API (a JSON array of actions)
NSError *error;
NSArray *actions = @[@{@"action": @"archive",
@"item_id": articleID}];
NSData *actionsAsJSONData = [NSJSONSerialization dataWithJSONObject:actions options:kNilOptions error:&error];
NSString *actionsAsJSONString = [[NSString alloc] initWithData:actionsAsJSONData encoding:NSUTF8StringEncoding];
NSDictionary *arguments = @{@"actions": actionsAsJSONString};
[[PocketAPI sharedAPI] callAPIMethod:@"send" withHTTPMethod:PocketAPIHTTPMethodPOST arguments:arguments handler:^(PocketAPI *api, NSString *apiMethod, NSDictionary *response, NSError *error) {
if (!error) {
NSLog(@"%@", response);
}
else {
NSLog(@"%@", error);
}
}];
哪个返回:
action_results" = (
1
);
status = 1;
但是,当我访问网站并登录时,我“存档”的文章仍然盯着我,没有存档。
最佳答案
这是(几乎)直接从my app获取的代码:
NSTimeInterval timestamp = [[NSDate date] timeIntervalSince1970];
NSDictionary *arguments = @{@"actions" : @[@{@"action" : @"archive",
@"item_id" : itemId,
@"time" : [NSString stringWithFormat:@"%ld", (long)timestamp]}]};
[self.pocketAPI callAPIMethod:@"send"
withHTTPMethod:PocketAPIHTTPMethodPOST
arguments:arguments
handler:^(PocketAPI *api, NSString *apiMethod, NSDictionary *response, NSError *error)
{
if (!error) {
// OK
} else {
// handle error
}
}];