我按照"在iOS和#34;上使用Core API中的说明安装了Dropbox API。对AppDelegate .h和.m以及我的ViewController进行了修改。没有调用任何API方法:以下是来自AppDelegate.m的代码:
// Dropbox API (Access Token: zzzzzzzzzzzzzzzzzzz)
DBSession *dbSession = [[DBSession alloc]
initWithAppKey:@"xxxxxxxxxxxx"
appSecret:@"yyyyyyyyyyyyyyy"
root:kDBRootAppFolder];
[DBSession setSharedSession:dbSession];
以下是ViewController.m中的代码:
- (IBAction)didPressLink {
if (![[DBSession sharedSession] isLinked]) {
[[DBSession sharedSession] linkFromController:self];
}
}
- (void)restClient:(DBRestClient *)client loadedMetadata:(DBMetadata *)metadata {
if (metadata.isDirectory) {
NSLog(@"Folder '%@' contains:", metadata.path);
for (DBMetadata *file in metadata.contents) {
NSLog(@" %@", file.filename);
}
}
}
- (void)restClient:(DBRestClient *)client loadMetadataFailedWithError:(NSError *)error {
NSLog(@"Error loading metadata: %@", error);
}
- (void)restClient:(DBRestClient *)client loadedFile:(NSString *)localPath contentType:(NSString *)contentType metadata:(DBMetadata *)metadata {
NSLog(@"File loaded into path: %@", localPath);
}
- (void)restClient:(DBRestClient *)client loadFileFailedWithError:(NSError *)error {
NSLog(@"There was an error loading the file: %@", error);
}
//#pragma mark - aImportTABDelimitedFile
- (IBAction)aImportFIle:(UIButton *)sender {
// dropbox stuff
if (![[DBSession sharedSession] isLinked]) {
[[DBSession sharedSession] linkFromController:self];
}
// set documentsPath -> DROPItTOme path in Dropbox
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
// list documents in Folder
[self.restClient loadMetadata:@"/"];
// download file
[self.restClient loadFile:@"https://www.dropbox.com/sh/<pathName>=0"
intoPath:documentsPath];
x,y,s,z和路径名都是正确的。我想要做的是获取DROPitTOme文件夹中的文件列表,其中包含1个.txt文件。我没有将didPressLink连接到任何按钮;相反,我将代码移动到-aImportFile方法,该方法有一个我单击的按钮(使用调试器和模拟器)。作为Dropbox API的菜鸟,我不知道出了什么问题。任何帮助将不胜感激。