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
Keith B.7
9 years agoHelpful | Level 7
How to re-link a user in API 2 (Handling Revoked Access Etc)
In API 1, I could offer the user an option to re-link (re-authorise) Dropbox if they run into issues because their access token had expired or been revoked. I could do this as follows:
First, I listened for the DBSession delegate method:
- (void)sessionDidReceiveAuthorizationFailure:(DBSession * )session userId:(NSString * )userId
Then, if I received this notification, I did two things:
1. Offer the user the chance to re-link Dropbox then and there (given that re-linking should be all that is required, as described in Core API Best Practises: <https://www.dropbox.com/developers-v1/core/bestpractices>).
2. Make note in a flag that there had been a session authorisation failure. Then, in a sync options menu, if this flag was YES, I would offer a "Re-Link Dropbox" option. In both cases, I could just call:
NSArray *userIds = [[DBSession sharedSession] userIds]; if (userIDs.count > 0) [[DBSession sharedSession] linkUserId:userIds[0] fromController:self];
Or, when calling this directly from the DBSession delegate method, I could pass in the userId directly because it was a parameter in the delegate method:
[[DBSession sharedSession] linkUserId:userId fromController:self];
What is the equivalent for re-linking following an authorisation failure owing to a revoked or expired access token in API 2?
At first I thought it was DropboxClientManager's -reauthorizeClient:, but that relies on grabbing the access token from [[DropboxClientsManager authorizedClient] transportClient].accessToken], and that won't be available (I believe) if authorisation has failed. And anyway, I believe this uses the very access token which has expired or been revoked in this situation. (In which case, what is -reauthorizeClient: for?)
Do I just call -authorizeFromController:controller:openURL:browserAuth: again to re-link in API 2, the same as for linking in the first place? Or is there a dedicated method like there was in API 1?
Thanks!
Keith
That's right. There's a simple example here, but you may want to handle the more specific cases (e.g., invalid access token versus suspended user) in the DBAUTHAuthError.
- Greg-DBDropbox Staff
That's right, reauthorizeClient isn't for this case. That's meant for when you want to retrieve an authorized client for a user account for which you already have an access token.
For the revoked access token case, you can just catch the authorization failure (the InvalidAccessToken DBAUTHAuthError from DBRequestAuthError) and then call authorizeFromController again to have the user re-link and get a new access token.
- Keith B.7Helpful | Level 7
Great, thanks for the clarification. So, instead of an equivalent of DBSession's -sessionDidReceiveAuthorizationFailure: delegate method, I check for DBError's -isAuthFailure in the response of any of the Dropbox requests? That makes sense, thanks!
- Greg-DBDropbox Staff
That's right. There's a simple example here, but you may want to handle the more specific cases (e.g., invalid access token versus suspended user) in the DBAUTHAuthError.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,888 PostsLatest Activity: 2 days 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!