如何从下面返回的项目中获取download_url或共享链接?修改了文件ID和名称,大小和日期,但我的要求是返回download_url或共享链接。
- (void)folderPickerController:(BoxFolderPickerViewController *)controller didSelectBoxItem:(BoxItem *)item
{
[self dismissViewControllerAnimated:YES completion:^{
// NSLog("%@",item);
// NSLog(@"%@", item.rawResponseJSON);
if ([BoxSDK sharedSDK].OAuth2Session.isAuthorized){
NSLog(@"authorized");
BoxAPIJSONFailureBlock failure = ^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSDictionary *JSONDictionary){
[self boxError:error];
};
NSDictionary *const queryParametersDictionary = @{@"fields" : @"item_collection"};
BoxFilesRequestBuilder *builder = [[BoxFilesRequestBuilder alloc] initWithQueryStringParameters:queryParametersDictionary];
BoxAPIJSONOperation *operation= [[BoxSDK sharedSDK].filesManager fileInfoWithID:item.modelID
requestBuilder:builder
success:nil
failure:failure];
}else{NSLog(@"fail");}
}];
答案 0 :(得分:0)
不确定您为什么需要download_url。您想将其公开给其他应用或用户吗?
如果您在项目rawResponseJSON(调试器:po [文件rawResponseJSON] [@" shared_link"])中看不到shared_link,那么很可能不会共享该文件。你需要先分享它。
如果您已经拥有BoxItem
,这是您的工作方式 BoxFileBlock success = ^(BoxFile *file) {
dispatch_async(dispatch_get_main_queue(), ^{
self.item = file;
NSDictionary *sharedLinkInfo = [self.item sharedLink];
// here is your urlString of the sharedLink
NSString *urlString = [sharedLinkInfo objectForKey:@"url"];
});
};
BoxFilesRequestBuilder *builder = [[BoxFilesRequestBuilder alloc] init];
builder.sharedLink = [[BoxSharedObjectBuilder alloc] init];
builder.sharedLink.access = BoxAPISharedObjectAccessOpen;
builder.sharedLink.canDownload = BoxAPISharedObjectPermissionStateEnabled;
builder.sharedLink.canPreview = BoxAPISharedObjectPermissionStateEnabled;
[self.sdk.filesManager editFileWithID:self.item.modelID
requestBuilder:builder
success:success
failure:failure];
理想情况下,您还希望提供故障块(此处省略)
还要确保您使用的是最新的SDK。它有一个小错误修复了昨天进入的sharedObjectFileBuilder。