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: 

Re: Re-authenticate using access token

Re-authenticate using access token

katharina
Explorer | Level 3

Hi, i get access token in my app using dropbox api. i want to reauthenticate in the same app on other device using these access token. How i can program it in objective c. Kinldy provide me solutions for this as i need it very badly.

 

Looking for needfull help.

 

regards

17 Replies 17

Greg-DB
Dropbox Staff

Are you using the official API v2 Objective-C SDK

 

If so, you can construct a DBUserClient on the fly using an existing access token using the DBUserClient.initWithAccessToken constructor. If you want to have the SDK store the access token for you, you can use DBOAuthManager.storeAccessToken

 

Note that access tokens are sensitive, as they enable access to the account, so make sure you transport the access token securely. That being the case, it may just be easier/safer to process the app authorization flow again on the other device. Also, note that it isn't reccomended to distribute an app with an access token for a particular account embedded in the app, as that can be extracted by a malicious user.

katharina
Explorer | Level 3
May i use sdk API v2 on xcode 7.3 version. Also i need link to download the latest sdk for ios.

katharina
Explorer | Level 3
i am using sdk 1.3 and api version is 1. And i write my whole in this. so i need a solution for this with coding part. I need it urgent.
Thanks

Greg-DB
Dropbox Staff

It sounds like you're using the iOS Core SDK, for Dropbox API v1. Dropbox API v1 is deprecated and being retired in a few months.

 

You should migrate to API v2 whenever you can. I recommend using the official API v2 Objective-C SDK.

 

This is technically possible with the iOS Core SDK as well though. You can store an existing access token using DBSession.updateAccessToken:

 

- (void)updateAccessToken:(NSString *)token accessTokenSecret:(NSString *)secret forUserId:(NSString *)userId;

 

You can then init a DBRestClient for that user normally.

katharina
Explorer | Level 3

Yes, i user the same method for reauthenticate, but i do not know what i need to call once it is autheticate from this method to fetch dropbox folder. My code is bellow

 

v1AccessToken i am storing in the sever and accessing when i start my app.

 

if(v1AccessToken.length>0)
    {
   //  [[DBSession sharedSession] updateAccessToken:v1AccessToken accessTokenSecret:v1AccessTokenSecret forUserId:ui];
      [[DBSession sharedSession] updateAccessToken:@"" accessTokenSecret:@"" forUserId:@""];
        if([DBSession sharedSession] != nil)
        {
        NSLog(@"Reauthenticating");
           [self performSelector:@selector(fetchAllDropboxData) withObject:nil afterDelay:0.2];
 
        }

 

 

how i can fetch the folder once it is authenticate usign this method. KInldy help me with coding part.

 

Regards

Greg-DB
Dropbox Staff
Once you've set the access token, you can get a DBRestClient using DBRestClient.initWithSession. From there, you use the client normally:

https://www.dropbox.com/developers-v1/core/start/ios

katharina
Explorer | Level 3

Hi Greg, I am using it in this way. But after all that it shows me that it session is expired and do you want to relink it.

if (![[DBSession sharedSession] isLinked])
{
[[DBSession sharedSession] updateAccessToken:@"" accessTokenSecret:@"" forUserId:@""];
self.restClient = [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
self.restClient.delegate = self;
NSLog(@"Reauthenticating");
[self performSelector:@selector(fetchAllDropboxData) withObject:nil afterDelay:0.2];
// [[DBSession sharedSession] linkFromController:self];
{
YourClientsViewController *control = [self.storyboard instantiateViewControllerWithIdentifier:@"YourClientsViewController"];
[self.navigationController pushViewController:control animated:YES];
}
else
{
[[DBSession sharedSession] linkFromController:self];
UIAlertView *view = [[UIAlertView alloc]initWithTitle:@"Account Login!" message:@"Your dropbox account has been login" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[view show];

if (!loadData)
{
loadData = @"";
}

// [MBProgressHUD showHUDAddedTo:self.view animated:YES];
[self performSelector:@selector(fetchAllDropboxData) withObject:nil afterDelay:0.2];
}



Can you please help me to modify this code so that it will work.

Greg-DB
Dropbox Staff
I'm not sure I follow. Can you share the full error/output you're getting?

Also, to clarify, you are entering the values in updateAccessToken:@"" accessTokenSecret:@"" forUserId:@"" and are just redacting them for the forum, correct?

You should, as the access token is sensitive, but I want to make sure you do have the right values there. The updateAccessToken parameter should be the OAuth 1 access token key, the accessTokenSecret parameter should be the OAuth 1 access token secret, and the forUserId should be your account's user ID.

katharina
Explorer | Level 3
Yes, i am entering the access token.
My query is that how you like to use this access token in the below method and display folder ,

self.restClient = [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
self.restClient.delegate = self;
Need more support?