【发布时间】:2014-07-10 00:49:48
【问题描述】:
我在使用 Dropbox api iOS 登录后尝试将 pdf 发送到我的个人 Dropbox 帐户时出错。
错误如下 “[警告] DropboxSDK:向 /1/files_put/kDBRootAppFolder/Music.pdf 发出请求时出错 - (400) 预期 'root' 为 'dropbox'、'sandbox' 或 'auto',得到了 u'kDBRootAppFolder'”
这是我在 Xcode iOS 项目中设置 Dropbox 所做的工作。
在我的 AppDelegate.m 中的 didFinishLaunchingWithOptions 我有以下内容:
DBSession *dbSession = [[DBSession alloc]
initWithAppKey:@"MYDROPBOXAPPKEY"
appSecret:@"MYDROPBOXAPPSECRET"
root:@"kDBRootAppFolder"]; // either kDBRootAppFolder or kDBRootDropbox
[DBSession setSharedSession:dbSession];
我还在 AppDelegate.m 中添加了以下内容:
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url
sourceApplication:(NSString *)source annotation:(id)annotation {
if ([[DBSession sharedSession] handleOpenURL:url]) {
if ([[DBSession sharedSession] isLinked]) {
NSLog(@"App linked successfully!");
// At this point you can start making API calls
}
[[NSNotificationCenter defaultCenter]
postNotificationName:@"isDropboxLinked"
object:[NSNumber numberWithBool:[[DBSession sharedSession] isLinked]]];
return YES;
}
// Add whatever other url handling code is requires here if applicale
return NO;
}
在我的 ViewController.m 中,我添加了以下内容并将其链接到 UIButton
- (void)didPressLink {
if (![[DBSession sharedSession] isLinked]) {
[[DBSession sharedSession] link];
}
}
我的 viewDidLoad 中也有这个
self.restClient = [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
self.restClient.delegate = self;
我可以点击我的按钮,收到 Dropbox 登录屏幕并使用我的个人帐户凭据成功登录。我成功登录时收到以下 NSLog 响应“应用链接成功!”请参阅上面包含此 NSLog 语句的 AppDelegate.m 中的代码。到目前为止一切顺利(我认为)
现在我有一个按钮,可以创建一个我想发送到 Dropbox 的 pdf。 pdf创建成功。现在我有这段代码可以将文件发送到保管箱(文件名是我的 pdf 的名称,在这种情况下恰好称为 Music.pdf)
// Upload file to Dropbox
NSString *destDir = @"/";
[self.restClient uploadFile:fileName toPath:destDir withParentRev:nil fromPath:localPath];
这是我收到“DropboxSDK:向 /1/fileops/delete 发出请求时出错 - (400) 预期 'root' 为 'dropbox'、'sandbox' 或 'auto' 的地方;得到了 'kDBRootAppFolder '" 为什么我错过了什么?
注意:一旦我使用我的个人凭据成功登录并收到此错误,如果我回到我的 AppDelegate.m 并将根目录从 kDBRootAppFolder 更改为沙盒并再次运行应用程序并尝试结束发送我的 Music.pdf文件到保管箱它会工作。这不是解决方案,因为如果我断开我的个人保管箱登录并尝试再次登录,它不会“应用链接成功!”如上所述,如果我将 root 保留为 kDBRootAppFolder。想法?........
【问题讨论】:
标签: ios xcode dropbox-api