我们需要为文件创建共享链接,然后检索该链接
我们可以在我们的应用程序中显示它。
我们能够为特定文件创建共享链接(我们可以看到它)
在Web上的Box帐户中)但我们无法检索sharedLink
通过API。虽然isShared
方法返回YES,但它始终为零。
从BoxObject.h
的头文件中我们发现这两种方法提供了
有关项目共享状态的必要信息。
@protocol BoxObject
// ...
// Information about the shared state of the item
@property (readonly, getter = isShared) BOOL shared;
@property (readonly) NSString *sharedLink;
//...
@end
这就是我们创建共享链接的方式。
[photo
isShared]
返回NO。[photo shareWithPassword:@"" message:@"" emails:[NSArray
arrayWithObject:@""] callbacks:^(id<BoxOperationCallbacks>
on1){...}];
[photo isShared]
会返回YES,但是[照片
sharedLink]返回nil 如果我们检查网络,我们可以看到该文件实际上是共享的,但我们 无法从Box SDK中检索sharedLink。
任何人都有同样的问题吗?
答案 0 :(得分:1)
根据已发布的代码和github上发现的信息here
,这对我有用- (void) getShareableLinkForFileId:(NSString *)fileId
{
BoxFileBlock fileSuccess = ^(BoxFile *file) {
NSDictionary *fileInfo = file.rawResponseJSON;
if (![fileInfo[@"shared_link"] isEqual:[NSNull null]]) {
NSDictionary *linkData = fileInfo[@"shared_link"];
//Do something with the link
} else {
// failure
}
};
BoxAPIJSONFailureBlock failure = ^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSDictionary *JSONDictionary) {
//Handle the failure
};
BoxFilesRequestBuilder *builder = [[BoxFilesRequestBuilder alloc] init];
BoxSharedObjectBuilder *sharedBuilder = [[BoxSharedObjectBuilder alloc] init];
sharedBuilder.access = BoxAPISharedObjectAccessOpen;
builder.sharedLink = sharedBuilder;
[[BoxSDK sharedSDK].filesManager editFileWithID:fileId requestBuilder:builder success:fileSuccess failure:failure];
}
答案 1 :(得分:0)
我能够通过刷新文件夹本身来获取共享链接。这是我提出的代码:
[boxFile shareWithPassword:@"" message:@"" emails:@[ @"" ] callbacks:^(id<BoxOperationCallbacks> on) {
on.after(^(BoxCallbackResponse response) {
if (response == BoxCallbackResponseSuccessful) {
[self.rootFolder updateWithCallbacks:^(id<BoxOperationCallbacks> on) {
on.after(^(BoxCallbackResponse response) {
BoxFile *updatedBoxFile = (BoxFile*)[self.rootFolder.children objectAtIndex:self.selectedIndexPath.row];
NSString *fileName = updatedBoxFile.name;
NSString *shareLink = updatedBoxFile.sharedLink;
NSLog(@"%@ [%@]: %@", fileName, updatedBoxFile.isShared ? @"YES" : @"NO", shareLink);
});
}];
} else {
[BoxErrorHandler presentErrorAlertViewForResponse:response];
}
});
}];
这是旧的v1 API。不确定它是否随着更新的v2而改变。
答案 2 :(得分:0)
您可以通过使用Box V2编辑其信息来创建共享链接:
Box2FolderBlock folderSuccess = ^(Box2Folder *folder) {
if (![[folder sharedLink] isEqual:[NSNull null]]) {
NSString *sharedUrl = [[folder sharedLink] objectForKey:Box2APIObjectKeyURL];
} else {
// failure
}
};
Box2FileBlock fileSuccess = ^(Box2File *file) {
if (![[file sharedLink] isEqual:[NSNull null]]) {
NSString *sharedUrl = [[file sharedLink] objectForKey:Box2APIObjectKeyURL];
} else {
// failure
}
};
Box2APIJSONFailureBlock failure = ^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSDictionary *JSONDictionary) {
};
BoxSharedObjectBuilder *sharedLinkObject = [[BoxSharedObjectBuilder alloc] init];
sharedLinkObject.access = BoxAPISharedObjectAccessOpen;
BoxAPIJSONOperation *operation;
if (isFile == NO) {
sharedLinkObject.canPreview = BoxAPISharedObjectPermissionStateEnabled;
BoxFoldersRequestBuilder *requestBuilder = [[BoxFoldersRequestBuilder alloc] init];
requestBuilder.sharedLink = sharedLinkObject;
operation = [boxSDK.foldersManager editFolderWithID:fileOrFolderId requestBuilder:requestBuilder success:folderSuccess failure:failure];
} else {
sharedLinkObject.canDownload = BoxAPISharedObjectPermissionStateEnabled;
BoxFilesRequestBuilder *requestBuilder = [[BoxFilesRequestBuilder alloc] init];
requestBuilder.sharedLink = sharedLinkObject;
operation = [boxSDK.filesManager editFileWithID:fileOrFolderId requestBuilder:requestBuilder success:fileSuccess failure:failure];
}