xCode Dropbox(400)错误

时间:2014-07-08 17:56:43

标签: ios xcode dropbox-api

使用dropbox api iOS登录后,我尝试将pdf发送到我的个人保管箱帐户时收到错误。

错误如下 " [警告] DropboxSDK:向/1/files_put/kDBRootAppFolder/Music.pdf发出错误请求 - (400)预期' root'要成为' dropbox',' sandbox',或者'自动',得到你的kDBRootAppFolder'"

以下是我在Xcode iOS项目中设置dropbox所做的工作。

在didFinishLaunchingWithOptions的AppDelegate.m中我有以下内容:

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响应" App链接成功!"请参阅具有此NSLog语句的AppDelegate.m中的上述代码。到目前为止一切顺利(我认为)

现在我有一个按钮,可以创建一个我想发送到Dropbox的pdf。 pdf创建成功。现在我有这个代码将文件发送到dropbox(文件名是我的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&#39 ;;得到了kDBRootAppFolder'"为什么我缺少什么?

注意:一旦我使用我的个人凭据成功登录并收到此错误,如果我回到AppDelegate.m并将根目录从kDBRootAppFolder更改为沙箱并再次运行应用程序并尝试结束发送我的音乐.pdf文件到dropbox它会工作。这不是解决方案,因为如果我与我的个人保管箱登录断开连接并尝试再次登录,则不会成功连接到应用程序!"如上所示,如果我将root保留为kDBRootAppFolder。想法?........

1 个答案:

答案 0 :(得分:1)

看起来你将kDBRootAppFolder作为字符串提供,而不是常量。 Dropbox SDK定义了kDBRootAppFolder常量,您可以将正确的“root”发送到Dropbox API本身。

所以,这个:

root:@"kDBRootAppFolder"];

应该是:

root:kDBRootAppFolder];