cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Is linking necessary to download files?

Is linking necessary to download files?

Ghulam A.
New member | Level 1

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?

30 Replies 30

Ghulam A.
New member | Level 1

Can you explain how to use /oauth/access_token and /account/info and /users/get_current_account? I also don't know how to tell if I'm using Oauth 1 or 2 and V1 or V2. I apologize as I am somewhat new to all that.

Greg-DB
Dropbox Staff

Are you using an SDK or library? If so, which?

Ghulam A.
New member | Level 1

I'm using the sdk following the tutorial on https://www.dropbox.com/developers-v1/core/start/ios which I now see has v1 in the URL but if you could explain that still, that would be great.

Greg-DB
Dropbox Staff

That SDK uses OAuth 1 and version 1 of the Dropbox API, a.k.a. the Core API. The DBRestClient.loadAccountInfo method corresponds to /account/info.

Ghulam A.
New member | Level 1

Okay so I'd put this somewhere:

DBRestClient.loadAccountInfo;

How would I view/retrieve the resulting info?

Ghulam A.
New member | Level 1

What is the corresponding function to get the access token secret? And is the access token you can generate from the account page the correct one to use with V1 or is it only for V2? (It doesn't give a token secret.)

Greg-DB
Dropbox Staff

I recommend working through the tutorial to see how to call methods in that SDK. For example:

[self.restClient loadMetadata:@"/"];

So, using loadAccountInfo would look something like:

[self.restClient loadAccountInfo];

And you'd need to implement these delegate methods to get the response:

- (void)restClient:(DBRestClient*)client loadedAccountInfo:(DBAccountInfo*)info;
- (void)restClient:(DBRestClient*)client loadAccountInfoFailedWithError:(NSError*)error;

 

The App Console only lets you generate an OAuth 2 access token, so that wouldn't suit your needs, as you need an OAuth 1 access token. You can get that by implementing the app authorization flow per the tutorial just to use for your account, and then pulling the access token out using DBSession.credentialStoreForUserId. (Again though, I should emphasize that this is not a recommended way of using the API, which is why this isn't particularly easy. If you just need to distribute content to the users of your app, a CDN might be a better solution.)

Ghulam A.
New member | Level 1

I figured out how to get the user id. All I need is the access token with secret and I'll be set. I'm not sure where to implement DBSession.credentialStoreForUserID though. I'm doing this within the example DBRoulette Xcode project. Would I call it like this?

[[DBSession sharedSession] credentialStoreForUserID];

Where would I put that and how would I retrieve the value for the access token? The most I can find online is this in terms of getting a value and I don't know where I would put that either.

DBSession.sharedSession().credentialStoreForUserId(userId).accessToken

If you could use the DBRoulette project for reference, that would help a lot.

By the way, thank you for sticking with me. I understand that this is not intended use, but I still wish the documentation was more straightforward. I don't see anything about access tokens in the tutorial you linked. I did follow that earlier for setting up my actual app.

Greg-DB
Dropbox Staff

You just need to call credentialStoreForUserID once to get your access token/secret, which you can do anywhere in the app, as long as the account is already linked. That would look like:

 MPOAuthCredentialConcreteStore *creds = [[DBSession sharedSession] credentialStoreForUserId:@"12345"];
NSLog(@"access token key: %@ secret: %@", creds.accessToken, creds.accessTokenSecret);

(Where 12345 is your user ID.)

Ghulam A.
New 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);
}
Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Ghulam A. New member | Level 1
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?