Cut the Clutter: Test Ignore Files Feature - sign up to become a beta tester here.
Forum Discussion
katharina
9 years agoExplorer | Level 3
Re-authenticate using access token
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
- Greg-DB9 years ago
Dropbox Community Moderator
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.
- katharina9 years agoExplorer | Level 3May i use sdk API v2 on xcode 7.3 version. Also i need link to download the latest sdk for ios.
- katharina9 years agoExplorer | Level 3i 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-DB9 years ago
Dropbox Community Moderator
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.
- katharina9 years agoExplorer | 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-DB9 years ago
Dropbox Community Moderator
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 - katharina9 years agoExplorer | 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-DB9 years ago
Dropbox Community Moderator
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. - katharina9 years agoExplorer | Level 3Yes, 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; - Greg-DB9 years ago
Dropbox Community Moderator
Once you've set the access token in the session, and retrieved a client with that session, as above, you can use that client to make calls.
The tutorial covers the basic of using a client to make calls. For example, to list a folder:
https://www.dropbox.com/developers-v1/core/start/ios#listing
What part specifically isn't working for you?
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,038 PostsLatest Activity: 3 years ago
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If 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!