假设我假设我的Box帐户有一个名为" TestFolder"的文件夹。我想获取该文件夹的文件夹ID,以便我可以从我的iOS应用程序中将文件写入其中。
我唯一的选择是遍历我的Box帐户的整个根目录以查找该文件夹名称吗?像这样的东西?
__block NSString *folderID;
BOXContentClient *contentClient = [BOXContentClient defaultClient];
BOXFolderItemsRequest *listAllInRoot = [contentClient folderItemsRequestWithID:BOXAPIFolderIDRoot];
[listAllInRoot performRequestWithCompletion:^(NSArray *items, NSError *error) {
if (error != nil) {
NSLog(@"Something bad happened when listing Box contents.");
return;
}
int ii,nItems = (int) [items count];
for (ii=0; ii<nItems; ii++) {
BOXItem *currItem = [items objectAtIndex:ii];
if ([[currItem name] isEqualToString:@"TestFolder"] && [currItem isFolder]) {
folderID = [currItem modelID];
break;
}
}
}];
答案 0 :(得分:0)
您可以使用Box API search endpoint按名称查询文件夹。如果搜索端点找到该文件夹,则响应将包含文件夹的ID。
以下是一个示例,说明如何使用Box iOS SDK进行此调用:
BOXContentClient *contentClient = [BOXContentClient defaultClient];
BOXSearchRequest *searchRequest = [contentClient searchRequestWithQuery:@"Test Folder" inRange:NSMakeRange(0, 1000)];
[searchRequest performRequestWithCompletion:^(NSArray *items, NSUInteger totalCount, NSRange range, NSError *error) {
// If successful, items will be non-nil and contain BOXItem model objects; otherwise, error will be non-nil.
}];