将iOS项目与Box SDK集成的问题

时间:2013-09-20 01:24:36

标签: ios oauth-2.0 box-api

我遇到将Box iOS SDK与我的项目集成的说明有问题。我已按照https://github.com/box/box-ios-sdk-v2上的说明操作,我已经让我的应用程序成功进行身份验证。现在,我被困在第一部分的Making API Calls部分(获取一个文件夹的孩子)。我的骨架应用程序刚才基本上有两个按钮:(1)链接; (2)生孩子。我链接后,它要求登录box.com;我做;然后它回到空屏幕。然后,我必须再次运行该程序,然后点击获取孩子。我试图查看此链接(iOS Box SDK BoxFolder.children always nil)和其他问题以找到解决方案,但未能实现。以下是每个例程:

- (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]; 

}

这是连接后的成功输出:

2013-09-16 17:18:45.585 BoxIntegratedApp-Without_Addition_of_Sample_Files [760:11303] - [BoxParallelAPIQueueManager enqueueOperation:]:在全局队列中排队POST api.box.com/oauth2/token 2013-09-16 17:18:45.585 BoxIntegratedApp-Without_Addition_of_Sample_Files [760:11303]链接!! 2013-09-16 17:18:45.587 BoxIntegratedApp-Without_Addition_of_Sample_Files [760:1730f] + [BoxAPIOperation globalAPIOperationNetworkThreadEntryPoint:]:{name = Box API Operation Thread,num = 4}已启动 2013-09-16 17:18:45.587 BoxIntegratedApp-Without_Addition_of_Sample_Files [760:1730f] - [BoxAPIOperation executeOperation]:BoxAPIOperation POST api.box.com/oauth2/token已启动 2013-09-16 17:18:45.588 BoxIntegratedApp-Without_Addition_of_Sample_Files [760:1730f] - [BoxAPIOperation executeOperation]:启动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 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已完成。从一组OAuth2依赖项中删除

2013-09-16 17:18:46.188 BoxIntegratedApp-Without_Addition_of_Sample_Files [760:1730f] - [BoxAPIOperation完成]:BoxAPIOperation POST api.box.com/oauth2/token结束状态3

这是在试图获得孩子后失败的输出:

2013-09-16 17:25:43.937 BoxIntegratedApp-Without_Addition_of_Sample_Files [794:11303] - [BoxParallelAPIQueueManager enqueueOperation:]:在全局队列中排队GET api.box.com/2.0/folders/0/items 2013-09-16 17:25:43.939 BoxIntegratedApp-Without_Addition_of_Sample_Files [794:15407] + [BoxAPIOperation globalAPIOperationNetworkThreadEntryPoint:]:{name = Box API Operation Thread,num = 3}已启动 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已启动 2013-09-16 17:25:46.180 BoxIntegratedApp-Without_Addition_of_Sample_Files [794:15407] - [BoxAPIOperation executeOperation]:启动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访问令牌已过期。 2013-09-16 17:25:46.670 BoxIntegratedApp-Without_Addition_of_Sample_Files [794:15407] - [BoxAPIAuthenticatedOperation connection:didReceiveResponse:]:重新排队无法验证的操作 2013-09-16 17:25:46.671 BoxIntegratedApp-Without_Addition_of_Sample_Files [794:15407] - [BoxParallelAPIQueueManager enqueueOperation:]:在全局队列中排队GET api.box.com/2.0/folders/0/items 2013-09-16 17:25:46.671 BoxIntegratedApp-Without_Addition_of_Sample_Files [794:15407] - [BoxAPIAuthenticatedOperation connection:didReceiveResponse:]:尝试自动OAuth2令牌刷新 2013-09-16 17:25:46.671 BoxIntegratedApp-Without_Addition_of_Sample_Files [794:15407] - [BoxParallelOAuth2Session performRefreshTokenGrant:]:访问令牌已过期:(null) 2013-09-16 17:25:46.671 BoxIntegratedApp-Without_Addition_of_Sample_Files [794:15407] - [BoxParallelOAuth2Session performRefreshTokenGrant:]:刷新令牌 2013-09-16 17:25:46.672 BoxIntegratedApp-Without_Addition_of_Sample_Files [794:15407] - [BoxParallelAPIQueueManager enqueueOperation:]:在全局队列中排队POST api.box.com/oauth2/token 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 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"操作无法完成。 (com.box.sdk.errordomain错误20000。)" 2013-09-16 17:25:46.677 BoxIntegratedApp-Without_Addition_of_Sample_Files [794:15407] - [BoxAPIOperation完成]:BoxAPIOperation GET api.box.com/2.0/folders/0/items已完成状态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已启动 2013-09-16 17:25:46.679 BoxIntegratedApp-Without_Addition_of_Sample_Files [794:15407] - [BoxAPIOperation executeOperation]:启动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 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已完成。从一组OAuth2依赖项中删除 2013-09-16 17:25:47.041 BoxIntegratedApp-Without_Addition_of_Sample_Files [794:15407] - [BoxAPIOperation完成]:BoxAPIOperation POST api.box.com/oauth2/token结束状态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已启动 2013-09-16 17:25:47.048 BoxIntegratedApp-Without_Addition_of_Sample_Files [794:15407] - [BoxAPIOperation executeOperation]:启动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 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"操作无法完成。 (com.box.sdk.errordomain错误20002。)"

2013-09-16 17:25:47.282 BoxIntegratedApp-Without_Addition_of_Sample_Files [794:15407] - [BoxAPIOperation完成]:BoxAPIOperation GET api.box.com/2.0/folders/0/items已完成状态3

我的基本目录中的文件位于box.com。如果有人能帮助我,我将非常感激。我一直试图明确地遵循指示。或者,如果您需要更多信息来诊断,请告诉我。非常感谢你。

维诺德

1 个答案:

答案 0 :(得分:1)

您拥有的错误代码是20002,表示此状态

访问令牌已过期且操作无法重新排队,因为它之前已经重新加入。

来自API API GIT文档,因此在执行此操作时应确保访问令牌有效。

另外,看看文件夹选择器你应该做那样的事情:

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