iphone - 袖珍 API : how to modify data using callAPIMethod?

标签 iphone ios objective-c pocket

我想使用 Pocket APIiOS SDK 编辑保存在 Pocket 的数据。 但是,虽然尝试了这种准备方法,却没有任何反应,反而还报错。

作为前提

  1. 可以使用其他 API (saveURL) 添加 URL。
  2. 已注册应用程序的权限为“添加”和“修改”。

有什么建议吗?谢谢。

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]);
                         }];

关于iphone - 袖珍 API : how to modify data using callAPIMethod?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19370727/

相关文章:

ios - Azure 移动服务推送不起作用

objective-c - 防止 UITableView 滚动到包含 textField 的单元格

ios - 无法将 UIViewController 限制为仅纵向

ios - 有没有办法从我的网站向 iPhone 发送推送通知?

iphone - 如何更改 Xcode 项目名称

ios - 在表格 View 的特定单元格中创建文本字段

ios - 无法在 Xcode 中使用 firebase auth 构建 flutter 应用程序

objective-c - OSX Cocoa 使用选项卡在 View 中的子控件之间导航不起作用

objective-c - ARC 是否足够聪明以释放父类(super class)中定义的 subview ?

iphone - 从 http 响应中的 NSMutableData 中提取数组