1
votes

I am having problems with the instructions to integrate the Box iOS SDK with my project. I have followed the instructions on https://github.com/box/box-ios-sdk-v2 and I have gotten my app to successfully authenticate. Now, I am stuck in the Making API Calls section on the first part (Get a folder's children). My skeleton app to get this working just has basically two buttons for now: (1) link; and (2) get children. After I link, it asks to login to box.com; I do; then it comes back to an empty screen. Then, I have to run the program again, and then hit get children. I attempted to look at this link (iOS Box SDK BoxFolder.children always nil) and other questions to find a solution, but have not been able to. Here are the routines for each of those:

- (IBAction)linkAction:(id)sender {

    UIViewController *authorizationController = [[BoxAuthorizationViewController alloc] initWithAuthorizationURL:[[BoxSDK sharedSDK].OAuth2Session authorizeURL] redirectURI:nil]; 
    [self presentViewController:authorizationController animated:YES completion:nil]; 
}

- (IBAction)getChildrenAction:(id)sender { 

    BoxCollectionBlock success = ^(BoxCollection *collection) 
    { 
        dispatch_sync(dispatch_get_main_queue(), ^{ 
            NSLog(@"CHILDREN SUCCESS!!!"); 
        }); 
    }; 

    BoxAPIJSONFailureBlock failure = ^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSDictionary *JSONDictionary)
    {

        dispatch_sync(dispatch_get_main_queue(), ^{ 
            // handle errors 
            NSLog(@"CHILDREN ERROR, error = %@", error); 
        }); 
    }; 

    NSString *folderID = BoxAPIFolderIDRoot; 

    [[BoxSDK sharedSDK].foldersManager folderItemsWithID:folderID requestBuilder:nil success:success failure:failure]; 

}

HERE IS THE SUCCESSFUL OUTPUT AFTER LINKING:

2013-09-16 17:18:45.585 BoxIntegratedApp-Without_Addition_of_Sample_Files[760:11303] -[BoxParallelAPIQueueManager enqueueOperation:]: enqueued POST api.box.com/oauth2/token on global queue 2013-09-16 17:18:45.585 BoxIntegratedApp-Without_Addition_of_Sample_Files[760:11303] LINKED!! 2013-09-16 17:18:45.587 BoxIntegratedApp-Without_Addition_of_Sample_Files[760:1730f] +[BoxAPIOperation globalAPIOperationNetworkThreadEntryPoint:]: {name = Box API Operation Thread, num = 4} started 2013-09-16 17:18:45.587 BoxIntegratedApp-Without_Addition_of_Sample_Files[760:1730f] -[BoxAPIOperation executeOperation]: BoxAPIOperation POST api.box.com/oauth2/token was started 2013-09-16 17:18:45.588 BoxIntegratedApp-Without_Addition_of_Sample_Files[760:1730f] -[BoxAPIOperation executeOperation]: Starting POST api.box.com/oauth2/token 2013-09-16 17:18:45.596 BoxIntegratedApp-Without_Addition_of_Sample_Files[760:11303] -[BoxAuthorizationViewController webViewDidFinishLoad:] 2013-09-16 17:18:46.186 BoxIntegratedApp-Without_Addition_of_Sample_Files[760:1730f] -[BoxAPIOperation connectionDidFinishLoading:]: BoxAPIOperation POST api.box.com/oauth2/token did finsh loading 2013-09-16 17:18:46.187 BoxIntegratedApp-Without_Addition_of_Sample_Files[760:1730f] -[BoxAPIQueueManager OAuth2OperationDidComplete:]: POST api.box.com/oauth2/token completed. Removing from set of OAuth2 dependencies

2013-09-16 17:18:46.188 BoxIntegratedApp-Without_Addition_of_Sample_Files[760:1730f] -[BoxAPIOperation finish]: BoxAPIOperation POST api.box.com/oauth2/token finished with state 3

HERE IS THE FAILED OUTPUT AFTER ATTEMPTING TO GET CHILDREN:

2013-09-16 17:25:43.937 BoxIntegratedApp-Without_Addition_of_Sample_Files[794:11303] -[BoxParallelAPIQueueManager enqueueOperation:]: enqueued GET api.box.com/2.0/folders/0/items on global queue 2013-09-16 17:25:43.939 BoxIntegratedApp-Without_Addition_of_Sample_Files[794:15407] +[BoxAPIOperation globalAPIOperationNetworkThreadEntryPoint:]: {name = Box API Operation Thread, num = 3} started 2013-09-16 17:25:46.173 BoxIntegratedApp-Without_Addition_of_Sample_Files[794:15407] -[BoxAPIOperation executeOperation]: BoxAPIOperation GET api.box.com/2.0/folders/0/items was started 2013-09-16 17:25:46.180 BoxIntegratedApp-Without_Addition_of_Sample_Files[794:15407] -[BoxAPIOperation executeOperation]: Starting GET api.box.com/2.0/folders/0/items 2013-09-16 17:25:46.670 BoxIntegratedApp-Without_Addition_of_Sample_Files[794:15407] -[BoxAPIAuthenticatedOperation connection:didReceiveResponse:]: OAuth2 access token is expired. 2013-09-16 17:25:46.670 BoxIntegratedApp-Without_Addition_of_Sample_Files[794:15407] -[BoxAPIAuthenticatedOperation connection:didReceiveResponse:]: Re-enqueueing operation that failed to authenticate 2013-09-16 17:25:46.671 BoxIntegratedApp-Without_Addition_of_Sample_Files[794:15407] -[BoxParallelAPIQueueManager enqueueOperation:]: enqueued GET api.box.com/2.0/folders/0/items on global queue 2013-09-16 17:25:46.671 BoxIntegratedApp-Without_Addition_of_Sample_Files[794:15407] -[BoxAPIAuthenticatedOperation connection:didReceiveResponse:]: Attempting automatic OAuth2 token refresh 2013-09-16 17:25:46.671 BoxIntegratedApp-Without_Addition_of_Sample_Files[794:15407] -[BoxParallelOAuth2Session performRefreshTokenGrant:]: access token expired: (null) 2013-09-16 17:25:46.671 BoxIntegratedApp-Without_Addition_of_Sample_Files[794:15407] -[BoxParallelOAuth2Session performRefreshTokenGrant:]: refreshing tokens 2013-09-16 17:25:46.672 BoxIntegratedApp-Without_Addition_of_Sample_Files[794:15407] -[BoxParallelAPIQueueManager enqueueOperation:]: enqueued POST api.box.com/oauth2/token on global queue 2013-09-16 17:25:46.673 BoxIntegratedApp-Without_Addition_of_Sample_Files[794:15407] -[BoxAPIOperation connectionDidFinishLoading:]: BoxAPIOperation GET api.box.com/2.0/folders/0/items did finsh loading 2013-09-16 17:25:46.677 BoxIntegratedApp-Without_Addition_of_Sample_Files[794:11303] CHILDREN ERROR, error = Error Domain=com.box.sdk.errordomain Code=20000 "The operation couldn’t be completed. (com.box.sdk.errordomain error 20000.)" 2013-09-16 17:25:46.677 BoxIntegratedApp-Without_Addition_of_Sample_Files[794:15407] -[BoxAPIOperation finish]: BoxAPIOperation GET api.box.com/2.0/folders/0/items finished with state 3 2013-09-16 17:25:46.679 BoxIntegratedApp-Without_Addition_of_Sample_Files[794:15407] -[BoxAPIOperation executeOperation]: BoxAPIOperation POST api.box.com/oauth2/token was started 2013-09-16 17:25:46.679 BoxIntegratedApp-Without_Addition_of_Sample_Files[794:15407] -[BoxAPIOperation executeOperation]: Starting POST api.box.com/oauth2/token 2013-09-16 17:25:47.039 BoxIntegratedApp-Without_Addition_of_Sample_Files[794:15407] -[BoxAPIOperation connectionDidFinishLoading:]: BoxAPIOperation POST api.box.com/oauth2/token did finsh loading 2013-09-16 17:25:47.040 BoxIntegratedApp-Without_Addition_of_Sample_Files[794:15407] -[BoxAPIQueueManager OAuth2OperationDidComplete:]: POST api.box.com/oauth2/token completed. Removing from set of OAuth2 dependencies 2013-09-16 17:25:47.041 BoxIntegratedApp-Without_Addition_of_Sample_Files[794:15407] -[BoxAPIOperation finish]: BoxAPIOperation POST api.box.com/oauth2/token finished with state 3 2013-09-16 17:25:47.047 BoxIntegratedApp-Without_Addition_of_Sample_Files[794:15407] -[BoxAPIOperation executeOperation]: BoxAPIOperation GET api.box.com/2.0/folders/0/items was started 2013-09-16 17:25:47.048 BoxIntegratedApp-Without_Addition_of_Sample_Files[794:15407] -[BoxAPIOperation executeOperation]: Starting GET api.box.com/2.0/folders/0/items 2013-09-16 17:25:47.281 BoxIntegratedApp-Without_Addition_of_Sample_Files[794:15407] -[BoxAPIOperation connectionDidFinishLoading:]: BoxAPIOperation GET api.box.com/2.0/folders/0/items did finsh loading 2013-09-16 17:25:47.281 BoxIntegratedApp-Without_Addition_of_Sample_Files[794:11303] CHILDREN ERROR, error = Error Domain=com.box.sdk.errordomain Code=20002 "The operation couldn’t be completed. (com.box.sdk.errordomain error 20002.)"

2013-09-16 17:25:47.282 BoxIntegratedApp-Without_Addition_of_Sample_Files[794:15407] -[BoxAPIOperation finish]: BoxAPIOperation GET api.box.com/2.0/folders/0/items finished with state 3

There are files in my base directory at box.com. I would very much appreciate if anyone could help me with this. I have been attempting to follow the instructions explicitly. Or please let me know if you need any more information to diagnose this. Thank you very much.

Vinod

1

1 Answers

1
votes

the error code you had is 20002 which represent this state

access token is expired and the operation cannot be reenqueued because it already has been reenqueued before.

that's from box API GIT docs,so you should make sure about your access token is valid when you perform this operation.

Also,take a look at folder picker you should do something like that :

   if ([BoxSDK sharedSDK].OAuth2Session.isAuthorized)
{
    // in order to avoid a short lag, jump immediatly to the file picker if we are already authorized
    [self presentBoxFolderPicker];
}
else
{
    BoxFolderBlock success = ^(BoxFolder * folder) {
        [self presentBoxFolderPicker];
    };
    BoxAPIJSONFailureBlock failure = ^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSDictionary *JSONDictionary){
        [self boxError:error];
    };
    // try sending a hearbeat
    [[BoxSDK sharedSDK].foldersManager folderInfoWithID:BoxAPIFolderIDRoot
                                         requestBuilder:nil
                                                success:success
                                                failure:failure];
}