我正在尝试在 Feedly API 上构建一个应用程序。为了能够将类别标记为已读,我需要将一些数据发布到 API。不过,我没有成功。
这是 API 需要作为输入的内容:
{
"lastReadEntryId": "TSxGHgRh4oAiHxRU9TgPrpYvYVBPjipkmUVSHGYCTY0=_1449255d60a:22c3491:9c6d71ab",
"action": "markAsRead",
"categoryIds": [
"user/c805fcbf-3acf-4302-a97e-d82f9d7c897f/category/design",
"user/c805fcbf-3acf-4302-a97e-d82f9d7c897f/category/photography"
],
"type": "categories"
}
这是我的方法:
- (void)markCategoryAsRead: (NSString*)feedID{
NSLog(@"Feed ID is: %@", feedID);
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
NSString *accessToken = [standardUserDefaults objectForKey:@"AccessToken"];
NSString *feedUrl = [NSURL URLWithString:@"https://sandbox.feedly.com/v3/markers"];
NSError *error = nil;
NSDictionary *tmp = [[NSDictionary alloc] initWithObjectsAndKeys:
@"markAsRead", @"action",
@"categories", @"type",
@[feedID], @"categoryIds",
@"1367539068016", @"asOf",
nil];
NSData *postdata = [NSJSONSerialization dataWithJSONObject:tmp options:0 error:&error];
NSLog(@"Postdata is: %@", postdata);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:feedUrl];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-type"];
[request addValue:accessToken forHTTPHeaderField:@"Authorization"];
//[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[url host]];
NSError *errror = [[NSError alloc] init];
NSHTTPURLResponse *response = nil;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&errror];
NSLog(@"Response code: %ld", (long)[response statusCode]);
if ([response statusCode] >= 200 && [response statusCode] < 300)
{
NSLog(@"It's marked as read.");
} else {
if (error) NSLog(@"Error: %@", errror);
NSLog(@"No success marking this as read. %@", response);
}
}
它一直抛出一个400
错误,说bad input
. 我究竟做错了什么?