1

我想使用带有iOS SDK的Pocket API编辑在 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)
                             }];
4

2 回答 2

2

删除 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]);
                         }];
于 2013-11-12T17:45:33.420 回答
0

可以使用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]);
                             }];
于 2014-07-20T15:17:38.083 回答