Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
Daniel A.39
9 years agoExplorer | Level 3
How to get OAuth2 access token from OAuth1 token and secret with API v2
All current users of our mobile app have OAuth1 token and secret stored for using their Dropbox account. With the migration to API v2, we must use OAuth2 access tokens. How can the OAuth1 token and...
- 9 years ago
No problem, that would look like this:
[DropboxClientsManager setupWithAppKey:@"APP_KEY"]; DBTransportClient *transportClient = [[DBTransportClient alloc] initWithAccessToken:nil selectUser:nil baseHosts:nil userAgent:nil backgroundSessionId:nil delegateQueue:nil appKey:@"APP_KEY" appSecret:@"APP_SECRET"]; [DropboxClientsManager authorizedClient:[[DropboxClient alloc] initWithTransportClient:transportClient]];[[DropboxClientsManager.authorizedClient.authRoutes tokenFromOauth1:@"OAUTH1_TOKEN_KEY" oauth1TokenSecret:@"OAUTH1_TOKEN_SECRET"] response:^(DBAUTHTokenFromOAuth1Result *result, DBAUTHTokenFromOAuth1Error *routeError, DBRequestError *error) { if (result) { NSLog(@"OAuth 2 access token: %@\n", result.oauth2Token); } else { NSLog(@"%@\n%@\n", routeError, error); } }];
Greg-DB
Dropbox Community Moderator
9 years agoNo problem, that would look like this:
[DropboxClientsManager setupWithAppKey:@"APP_KEY"];
DBTransportClient *transportClient = [[DBTransportClient alloc] initWithAccessToken:nil
selectUser:nil
baseHosts:nil
userAgent:nil
backgroundSessionId:nil
delegateQueue:nil
appKey:@"APP_KEY"
appSecret:@"APP_SECRET"];
[DropboxClientsManager authorizedClient:[[DropboxClient alloc] initWithTransportClient:transportClient]];
[[DropboxClientsManager.authorizedClient.authRoutes tokenFromOauth1:@"OAUTH1_TOKEN_KEY" oauth1TokenSecret:@"OAUTH1_TOKEN_SECRET"] response:^(DBAUTHTokenFromOAuth1Result *result, DBAUTHTokenFromOAuth1Error *routeError, DBRequestError *error) {
if (result) {
NSLog(@"OAuth 2 access token: %@\n", result.oauth2Token);
} else {
NSLog(@"%@\n%@\n", routeError, error);
}
}];Steve L.
9 years agoHelpful | Level 6
Can you point us to an example of using this with the new 3.0 SDK changes mentioned in https://github.com/dropbox/dropbox-sdk-obj-c/releases/tag/3.0.0 ?
- Greg-DB9 years ago
Dropbox Community Moderator
In the latest version of the SDK, the equivalent code would be:
DBTransportDefaultConfig *transportClient = [[DBTransportDefaultConfig alloc] initWithAppKey:@"APP_KEY" appSecret:@"APP_SECRET"]; [DBClientsManager setupWithTransportConfig:transportClient];
[[DBClientsManager.authorizedClient.authRoutes tokenFromOauth1:@"OAUTH1_TOKEN_KEY" oauth1TokenSecret:@"OAUTH1_TOKEN_SECRET"] setResponseBlock:^(DBAUTHTokenFromOAuth1Result *response, DBAUTHTokenFromOAuth1Error *routeError, DBRequestError * error) { if (response) { NSLog(@"OAuth 2 access token: %@\n", response.oauth2Token); } else { NSLog(@"%@\n%@\n", routeError, error); } }];If you are migrating from an old official SDK though, we recently added a helper that can automatically migrate those stored tokens:
https://github.com/dropbox/dropbox-sdk-obj-c#migrating-from-api-v1
- Steve L.9 years agoHelpful | Level 6
Thanks Greg, that last link helps a lot.
BTW, there's a typo in Migrating OAuth tokens from earlier SDKs, in the unsuccessfullyMigratedTokenData code. The format either has an extra %@ at the start or there is a missing argument.
NSLog(@"%@DropboxUserID: %@, AccessToken: %@, AccessTokenSecret: %@, StoredAppKey: %@", tokenData[0],
- Stephen C.149 years ago
Dropbox Staff
Thanks for letting us know, Steve. This should be updated now!
Let us know if you run into any issues migrating.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
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, Facebook or Instagram.
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!