We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
Aibek D.
10 years agoNew member | Level 1
[SwiftyDropbox] Storing v2 accountId in DropboxAccessToken instead of v1 userId
Not really a critical issue, but for our project it brought some inconveniences.
So, currently DropboxAccessToken stores user id from API v1, while Users.Account.accountId stores API v2 account id.
Our app has it's own account system and it supports usage of multiple accounts at the same time. Every account can link multiple dropbox accounts and every user can go to a screen where he can add another dropbox account or remove linked dropbox account.
In order for user to understand which dropbox account he unlinks, we use and display e-mails. To get account's email, we make a call to DropboxClient.users.getCurrentAccount(). So far so good.
But making requests takes time. Plus we have our own file browser which supports switching between accounts, and we use e-mails there too. So it makes sense to cache Users.FullAccount in order to have fast access to e-mails.
With API v1 we had a small "database" with DBAccountInfo, where we could make a request "give us a cached account for userId". With API v2 "database" implementation gets harder:
1) Create a subclass of Users.FullAccount, which will have a property "APIv1userId", and create a subclass of FullAccountSerializer
1) get access token, get userId
2) create client with userId, call getCurrentAccount()
3) Create an instance of FullAccount subclass, and use APIv1userId property.
Too much work for something simple as caching and differentiating which account info belongs to which account.
For the same reason I would like to ask you to make functions because we in order to cache FullAccount, we serialize it first.
prepareJSONForSerialization()
objectToJSON()
So, is there a possibility to SwiftyDropbox will use v2 account id in access tokens? This would simplify things a lot and remove one very unclear moment: DropboxAccessToken.userId and FullAccount.accountId are different things. Intuitively, people think that they are the same.
And, of course, if you have a better solution for our "cache database", I will be glad to hear it.
Thanks in advance, Gregory!
5 Replies
- Aibek D.10 years agoNew member | Level 1
Okay, now that I actually implemented "database" that supports API v2, I think that the SwiftyDropbox improvement would be to:
1) Add "v1APIuserId" (or something like this) property to Users.FullAccount, which will contain userId from v1 API.
2) make prepareJSONForSerialization(), objectToJSON() functions public, in order to simplify serialization, caching and storing FullAccount for client code.
Right now, they're private and to implement storing, I ended up with simply copy-pasting those functions.
3) Add explicit initializers for StringSerializer and some other serializers in order to simplify subclassing.
Although StringSerializer is a public class, there's no way client code can use it, because there's no accessible initializers. Ditto for a bunch of other serializers. I also had to copy-paste StringSerializer in order to implement caching.
And, of course, these are just my thoughts, I hope you will consider these thoughts sane and good.
- Greg-DB10 years ago
Dropbox Community Moderator
Thanks for the writeup Aibek! I'm sending these along as feature requests, though I can't make any promises about if or when they'd be implemented.
One note, it doesn't sounds like you necessarily are, but just to be sure/for anyone else reading, you definitely shouldn't rely on email address as an account identifier in your app, as it can change on Dropbox's side. Either of the other account IDs (user ID or account ID) are better suited for that. Email is fine for display purposes though.
- Greg-DB10 years ago
Dropbox Community Moderator
The serialization methods are now public in version 3.1.0.
- fengzhazha9 years agoNew member | Level 2
Hi Greg,
Are you saying that userID is sufficient to distinguish a unique Dropbox account? As our product were storing this information(userID) since V1, it is difficult for us to switch to another value(accountID) now unless we drop all our exisitng connected Dropbox accounts.
Thank you for the help.
Chao
- Greg-DB9 years ago
Dropbox Community Moderator
Yes, both user ID and account ID uniquely identify Dropbox accounts.
By the way, you can call getCurrentAccount (or the equivalent method/endpoint in your platform) for each stored account to map from user ID to account ID.
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!