Shin Morichika
Shin Morichika

Reputation: 11

Pocket API: how to modify data using callAPIMethod?

I would like to edit the data saved at Pocket using Pocket API with iOS SDK. However, although the preparation method is tried, no response and error also come on the contrary.

As a premise

  1. URLs can be added using other API (saveURL).
  2. Permissions of the registered application are 'Add' and 'Modify'.

Is there any advice? Thanks.

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

Upvotes: 1

Views: 405

Answers (2)

koishi
koishi

Reputation: 1

Can use the NSDictionary to 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]);
                             }];

Upvotes: 0

MartinMcB
MartinMcB

Reputation: 51

Drop the the API version, consumer_key & access_token. These are appended by the 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]);
                         }];

Upvotes: 2

Related Questions