gpt4 book ai didi

iOS BoxSDK 为 sharedLink 返回 nil

转载 作者:可可西里 更新时间:2023-11-01 03:19:57 25 4
gpt4 key购买 nike

我们需要为一个文件创建一个共享链接,然后检索该链接,这样我们可以在我们的应用程序中显示它。我们能够为特定文件创建共享链接(我们可以看到它在网络上的 Box 帐户内),但我们无法检索共享链接通过 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

这就是我们创建共享链接的方式。

  1. 找到我们想要共享的 BoxFile,我们将该对象称为照片之前调用方法 shareWithPassword:message:emails:callbacks:, [photo
    isShared]
    返回编号。
  2. 我们调用[photo shareWithPassword:@"" message:@"" emails:[NSArray
    arrayWithObject:@""] callbacks:^(id<BoxOperationCallbacks>
    on1){...}];
  3. 在 on1.after 我们检查 response == BoxCallbackResponseSuccessful然后我们调用 [photo updateWithCallbacks:^(idon2){..}]
  4. 在 on2.after 我们检查是否 response == BoxCallbackResponseSuccessful
  5. 成功响应[photo isShared]返回 YES 但 [照片sharedLink] 返回 nil

如果我们在 Web 上查看,我们可以看到该文件实际上是共享的,但我们无法从 Box SDK 中检索 sharedLink。

有人遇到同样的问题吗?

最佳答案

这对我有用,基于已经发布的代码和在 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];
}

关于iOS BoxSDK 为 sharedLink 返回 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15221081/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com