我想使用带有iOS SDK的Pocket API编辑保存在Pocket的数据。但是,尽管尝试了制备方法,但相反,也没有响应和错误。
作为前提
- 可以使用其他 API (saveURL) 添加 URL。
- 已注册应用程序的权限为"添加"和"修改"。
有什么建议吗?谢谢。
NSError* error;
NSArray *actions = @[@{ @"action": @"delete", @"item_id": @"456853615" }];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject: actions
options: kNilOptions
error: &error];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding: NSUTF8StringEncoding];
// On ios simulator access_token is saved in NSUserDefaults, but on device in keychain.
// see https://github.com/Pocket/Pocket-ObjC-SDK/blob/master/SDK/PocketAPI.m#L718
NSString *accessToken = [[NSUserDefaults standardUserDefaults] objectForKey: @"PocketAPI.token"];
NSDictionary* argumentDictionary = @{@"consumer_key": @"<MY_CONSUMER_KEY>",
@"access_token": accessToken,
@"actions": jsonString};
[[PocketAPI sharedAPI] callAPIMethod: @"v3/send"
withHTTPMethod: PocketAPIHTTPMethodPOST
arguments: argumentDictionary
handler: ^(PocketAPI *api, NSString *apiMethod, NSDictionary *response, NSError *error){
NSLog(@"response %@", [response description]); // response (null)
NSLog(@"error %@", [error localizedDescription]); // response (null)
}];
删除 API 版本,consumer_key & access_token。这些由 SDK 追加。
NSError* error;
NSArray *actions = @[@{ @"action": @"delete", @"item_id": @"456853615" }];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject: actions
options: kNilOptions
error: &error];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding: NSUTF8StringEncoding];
NSDictionary* argumentDictionary = @{@"actions":jsonString};
[[PocketAPI sharedAPI] callAPIMethod:@"send"
withHTTPMethod:PocketAPIHTTPMethodPOST
arguments:argumentDictionary
handler:^(PocketAPI *api, NSString *apiMethod, NSDictionary *response, NSError *error){
NSLog(@"response %@", [response description]);
NSLog(@"error %@", [error localizedDescription]);
}];
可以使用 NSDictionary 来 argumentDictionary。
NSDictionary *argumentDictionary = @{@"actions" : @[@{@"action" : @"delete",
@"item_id" : @"456853615"}]};
[[PocketAPI sharedAPI] callAPIMethod:@"send"
withHTTPMethod:PocketAPIHTTPMethodPOST
arguments:argumentDictionary
handler:^(PocketAPI *api, NSString *apiMethod, NSDictionary *response, NSError *error){
NSLog(@"response %@", [response description]);
NSLog(@"error %@", [error localizedDescription]);
}];