You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
Ghulam A.
9 years agoNew member | Level 1
Is linking necessary to download files?
Is it possible to download files from my app folder (Dropbox) to my app without linking an account? If so, how would I do that?
Ghulam A.
9 years agoNew member | Level 1
Okay, that did allow me to get an access token and secret. However, I still don't seem to be able to retrieve a file from my folder using this method. If I login normally to link my dropbox, it does work. (I basically pull a text file from my Dropbox and display the text.) I'm not sure what I'm doing wrong here. The one thing I did notice was that I get a new access token and secret every time I login normally. Do the tokens expire? Anyways, here is my code cutting out irrelevant portions and replacing sensitive info:
In my app delegate:
.h
#import <UIKit/UIKit.h>
@interface AppDelegate : NSObject <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
.m
#import "AppDelegate.h"
#import <DropboxSDK/DropboxSDK.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
DBSession *dbSession = [[DBSession alloc]
initWithAppKey:@"key"
appSecret:@"secret"
root:kDBRootAppFolder]; // either kDBRootAppFolder or kDBRootDropbox
[DBSession setSharedSession:dbSession];
//[[DBSession sharedSession] unlinkAll];
[dbSession updateAccessToken:@"token" accessTokenSecret:@"token secret" forUserId:@"id number"];
}
@end
In my view controller:
.h file
#import <UIKit/UIKit.h>
@class DBRestClient;
@interface homeVC : UIViewController
{
DBRestClient *restClient;
}
@end
.m file
#import "homeVC.h"
#import <DropboxSDK/DropboxSDK.h>
@interface homeVC () <UITableViewDataSource, UIAccelerometerDelegate, DBRestClientDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) DBRestClient *restClient;
@end
@implementation homeVC
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* path2 = [documentsDirectory stringByAppendingPathComponent:
[NSString stringWithFormat:@"%@", @"Welcome.txt"]];
[self.restClient loadMetadata:@"/"];
[self.restClient loadFile:@"/Welcome.txt" intoPath:path2];
NSString* content = [NSString stringWithContentsOfFile:path2
encoding:NSUTF8StringEncoding
error:NULL];
NSLog(@"%@",content);
}
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,879 PostsLatest Activity: 3 hours agoIf you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!