We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
Kevin B.36
2 months agoCollaborator | Level 9
Find DBID on Local PC
Application Affected
My own app
Device
Windows 11 VM
Operating System/Browser (if using the web)
Windows 11
Dropbox App Version (if using the app)
Latest
Question or Issue
We have an app that uses the Dropbox API quite significantly. The user must signin to our app using the Dropbox API and our own login code.
It's possible that the user has logged into the Web version of the app at some time, but is using a different account on the PC App. This causes considerable grief in our system where, on install say, the system goes off into the web system and says you have a record with this account, but we cannot find the details, but the user installing the system notes that their local (PC App) account has no records associated with it. Such a use case occurs during testing, but it is perfectly plausible that a user could have their business and one or more personal Dropbox accounts, so definitely a use case that can occur in the real world.
The simplest way to prevent this is that, on startup, verify that the DBID returned by the API is the same as the local account (ie. the installed APP).
Simple question: Where on the local PC are the local app account details kept?
Ideally it would be the DBID, but worst case it could be the associated email address? I am not having any luck with my internet searches for this info (AI does not know the difference between the DBID and the Host ID in the info.json file).
EDIT: Of course if we could also find the associated email address (ie. the login to the web email address and the account associated with the app email address) then we could compare. Email address is unique in this context so if they differed same as a differing DBID. Again, I cannot seem to determine the email address associated with the local Windows Dropbox app?
Hi again Kevin B.36,
I tried to reproduce your issue, but honestly unsuccessful.
About your speculations: Once setup correctly, Dropbox application doesn't change that file if you haven't forced it (link/unlink account), so "before the Dropbox app has initialized it" in context of just starting - impossible in fact. There is something else possible though. Since that file becomes locked temporary (for short time) at Dropbox application stat moment, your application may be trying read the file at the same time without set enough timeout. On boot time, this lock time may be longer that the default timeout of the sqlite3 library you're using. You may try set explicitly longer connect timeout. It's good idea to trace possible changes in this file and update your application status if/when need (not just to fetch the info at beginning - user may change account at any time) or to check what's there exactly when need at any time your application has to check it (so avoiding keep any status about the account of Dropbox application together with possible hidden bugs).
I used following simple script to check what's going on:
#!/bin/python3 ############################################################################### # Checking for matching third party application account and local Dropbox # application account. # ----------------------------------------------------------------------------- # Author: Здравко # www.dropboxforum.com/t5/user/viewprofilepage/user-id/422790 ############################################################################### from dropbox import Dropbox from pathlib import Path from sqlite3 import connect, OperationalError from tkinter import messagebox # Take a look on your application in https://www.dropbox.com/developers/apps APPLICATION_KEY='PUT YOUR KEY HERE' APPLICATION_SECRET=None # Left None if PKCE is in use or set the actual secret. # Fetch the refresh token used in your main application or create such by hand # (take a look here: # https://www.dropboxforum.com/discussions/101000014/issue-in-generating-access-token/592667/replies/592921 # for instance). REFRESH_TOKEN='PUT YOUR TOKEN HERE' APEX_PATH='PUT YOUR apex.sqlite3 PATH HERE' client=Dropbox(oauth2_refresh_token=REFRESH_TOKEN, app_key=APPLICATION_KEY, app_secret=APPLICATION_SECRET) userInfo=client.users_get_current_account() dbid=userInfo.account_id email=userInfo.email apex=Path(APEX_PATH).expanduser().absolute() try: con = connect(f"file:{apex}?mode=ro", uri=True, timeout=50.0) except OperationalError as e: messagebox.showerror('Check Account', "Local Dropbox application is not yet installed or " f"it is not completely configured!\n\n{e}"); exit(1) try: blobs=list(row[0] for row in con.execute("SELECT value FROM apex_stormcrow")) except OperationalError as e: messagebox.showerror('Check Account', f"Local Dropbox application seems not yet completely configured!\n\n{e}"); con.close() exit(1) con.close() def getDbId(rawData): i=rawData.find(b'dbid:') length=rawData[i-1] return rawData[i:i+length].decode() localDbIds=list(getDbId(blob) for blob in blobs if blob.find(b'dbid:') > 0) if len(localDbIds) == 0: messagebox.showerror('Check Account', "Local Dropbox application is not yet completely configured!\n\n" "No any IDs found."); exit(1) if localDbIds.count(dbid) == 1: messagebox.showinfo('Check Account', "Found local Dropbox application link " "to current third party application account:\n\n" f"account id: {dbid}\n" f"email: {email}"); else: messagebox.showinfo('Check Account', "Current third party application account:\n\n" f"account id: {dbid}\n" f"email: {email}\n\n" "cannot be found in local Dropbox application link(s):\n\n" f"{localDbIds}")Everything works all the time correctly for me. You may try it simultaneous in time of your application test to see possible differences and feed your further debugging. Post strange results of above script if you decide to test it and something suspicious comes up.
All the best!
10 Replies
- Nancy2 months ago
Dropbox Community Moderator
Welcome back to our Community, Kevin B.36!
If you wish to see the email address that's linked to the local Dropbox desktop app, you can do so with these steps.
If I’ve misunderstood something though, and you wish to achieve something different, let me know and I’ll move your request to the API section of our forum.
Keep me in the loop.
- Kevin B.3629 days agoCollaborator | Level 9
Hi Nancy,
Yes you have misunderstood.
This is for Windows: In my app (so this needs to be done programatically), I can be signed in on the Dropbox.com website as userA, BUT the app could be signed in as User B. When I run my app it displays the ALLOW window if Im already signed in to WEB Dropbox. My app then goes barrelling along with the local Dropbox credentials and sees the mismatch and objects. Yes, it is possible to be logged into Account A (which the API calls will return details of) and be signed into Account B using the local APP.
I can get the web DBID using the API easy enough. I need to get the local PC Account's DBID. I have found a file apex.sqlite3 here (which we can parse and extract the local PC DBID):
C:\Users\USERNAME\AppData\Local\Dropbox\apex.sqlite3
But this file is not always there (I'm not sure of the rules associated with its existence), but I do know at times when we install our Windows APP, there is no apex.sqlite3 file. There is an info.json file that has some details, but not the email address (which we could also use to differentiate) or the DBID.
So my question is: What is the simplest way to get the account details (email/DBID) of the local (Not Web/API) of the Dropbox Account?
- DB-Des28 days ago
Dropbox Community Moderator
Hi Kevin B.36
The kind of custom-built app you’re describing falls outside the scope of what the Dropbox API Developer Support team can directly help design or implement. Our support is limited to assisting with the Dropbox API itself.
If you have specific questions about the Dropbox API (e.g., which endpoints to use, how to structure a particular request, or how to interpret a response), feel free to share those details and we’ll be happy to help.
- Здравко28 days agoLegendary | Level 20
Hi Kevin B.36,
Unfortunately the feature you are asking for is something not supported officially. Most probably (I'm pretty sure) there is such option, but it's neither part of Dropbox API nor common use case. If I have to bet, the developers of Dropbox application are too lazy to give answer to your question (or maybe the question is not forwarded there at all). 🤷 Who knows...
Anyway... There are some tricks you may use to achieve what you want. In the same folder, where you found 'apex.sqlite3' out, is another database file 'sync_history.db' (residing in subfolder 'instance1' usually) responsible to keep track of the latest sync activities of Drobox application. In the only table 'sync_history', you may find field 'server_path' of type TEXT'. Select the first row with non empty 'server_path' field (empty fields are for deleted files) where you may get the namespace id in use for target account (it is the numeric part before first colon). Comparing this value with the equivalent one received online, through /2/users/get_current_account usage, will let you determine whether the accounts are different or it's the same one. 😉 In spite of different accounts can share some namespace (in form of shared folder for instance), the namespace of account's root is always unique and cannot be shared.
I hope this helps.
- Здравко28 days agoLegendary | Level 20
Kevin B.36, when you say "I do know at times when we install our Windows APP, there is no apex.sqlite3 file", can you clarify when such a situation happens? (some steps to reproduce)
As far as I know only possible case would be when Dropbox application has never been installed at that point or not yet running (linked to some account). Did you see some other situation(s)? If so, can you share?
- Kevin B.3627 days agoCollaborator | Level 9
Hi,
This happened with one of our testers, he reported on a clean install on a clean system there was no apex.sqlite3.
I’m not sure if this is simply an outlier, but let me be clear, are you saying if the app is running on my PC, there will be an apex.sqlite3 file?
thanks, Kevin
- Здравко27 days agoLegendary | Level 20
When you (or your tester) install your application on "clean install" and there is not yet Dropbox application installed, of course, where will apex.sqlite3 will come from?! 🙂 (if that's the case)
The Dropbox folder (both that containing your data and that contain application setting) and everything contained inside are created by Dropbox application installed and running. Wow.. that's confusing.. does your tester really surprise that the file is missing while responsible application is missing (or not yet setup)??? 😂
Of course, to be available that file and to contain valid id there, valid setup (link to account) is need in addition to just install! What would be such id for while there is no any account yet?! 😉
Yes, there should be apex.sqlite3 in condition Dropbox application has been setup correctly (or will come up once this happens as far as I know) if you haven't found something else. Please, share it if you have such.
Good luck!
- Kevin B.3624 days agoCollaborator | Level 9
Hi,
No wrong (my bad - I misunderstood what the tester said). The Dropbox App is running (and it is) the file apex.sqlite3 is available. BUT just at startup of our app, the DBID was NOT in the Apex.sqlite3 file. This I suspect is simply a timing issue.
Our app starts when the system starts and so does the Dropbox App. It's possible (and I'm speculating here) there is a race condition inadvertently setup where our app reads the apex.sqlite3 file before the Dropbox app has initialised it (again spculation).
For the most part it works fine and I'm at the point where we can live with that. I'll experiment with doing a retry some ms later if the apex.sqlite3 file does not have the DBID.
Tnaks for your replies, they were very helpful
Kevin
- Здравко24 days agoLegendary | Level 20
Hi again Kevin B.36,
I tried to reproduce your issue, but honestly unsuccessful.
About your speculations: Once setup correctly, Dropbox application doesn't change that file if you haven't forced it (link/unlink account), so "before the Dropbox app has initialized it" in context of just starting - impossible in fact. There is something else possible though. Since that file becomes locked temporary (for short time) at Dropbox application stat moment, your application may be trying read the file at the same time without set enough timeout. On boot time, this lock time may be longer that the default timeout of the sqlite3 library you're using. You may try set explicitly longer connect timeout. It's good idea to trace possible changes in this file and update your application status if/when need (not just to fetch the info at beginning - user may change account at any time) or to check what's there exactly when need at any time your application has to check it (so avoiding keep any status about the account of Dropbox application together with possible hidden bugs).
I used following simple script to check what's going on:
#!/bin/python3 ############################################################################### # Checking for matching third party application account and local Dropbox # application account. # ----------------------------------------------------------------------------- # Author: Здравко # www.dropboxforum.com/t5/user/viewprofilepage/user-id/422790 ############################################################################### from dropbox import Dropbox from pathlib import Path from sqlite3 import connect, OperationalError from tkinter import messagebox # Take a look on your application in https://www.dropbox.com/developers/apps APPLICATION_KEY='PUT YOUR KEY HERE' APPLICATION_SECRET=None # Left None if PKCE is in use or set the actual secret. # Fetch the refresh token used in your main application or create such by hand # (take a look here: # https://www.dropboxforum.com/discussions/101000014/issue-in-generating-access-token/592667/replies/592921 # for instance). REFRESH_TOKEN='PUT YOUR TOKEN HERE' APEX_PATH='PUT YOUR apex.sqlite3 PATH HERE' client=Dropbox(oauth2_refresh_token=REFRESH_TOKEN, app_key=APPLICATION_KEY, app_secret=APPLICATION_SECRET) userInfo=client.users_get_current_account() dbid=userInfo.account_id email=userInfo.email apex=Path(APEX_PATH).expanduser().absolute() try: con = connect(f"file:{apex}?mode=ro", uri=True, timeout=50.0) except OperationalError as e: messagebox.showerror('Check Account', "Local Dropbox application is not yet installed or " f"it is not completely configured!\n\n{e}"); exit(1) try: blobs=list(row[0] for row in con.execute("SELECT value FROM apex_stormcrow")) except OperationalError as e: messagebox.showerror('Check Account', f"Local Dropbox application seems not yet completely configured!\n\n{e}"); con.close() exit(1) con.close() def getDbId(rawData): i=rawData.find(b'dbid:') length=rawData[i-1] return rawData[i:i+length].decode() localDbIds=list(getDbId(blob) for blob in blobs if blob.find(b'dbid:') > 0) if len(localDbIds) == 0: messagebox.showerror('Check Account', "Local Dropbox application is not yet completely configured!\n\n" "No any IDs found."); exit(1) if localDbIds.count(dbid) == 1: messagebox.showinfo('Check Account', "Found local Dropbox application link " "to current third party application account:\n\n" f"account id: {dbid}\n" f"email: {email}"); else: messagebox.showinfo('Check Account', "Current third party application account:\n\n" f"account id: {dbid}\n" f"email: {email}\n\n" "cannot be found in local Dropbox application link(s):\n\n" f"{localDbIds}")Everything works all the time correctly for me. You may try it simultaneous in time of your application test to see possible differences and feed your further debugging. Post strange results of above script if you decide to test it and something suspicious comes up.
All the best!
- Kevin B.3623 days agoCollaborator | Level 9
Hi,
Apologies having trouple pasting in your monika with cyrillic alphabet.
Thank you for taking the time to explore this issue in a most comprehensive way, I could not have asked for a better response. We are now quite confidant that we can pickup the DBID and/or the email address of the user on the local machine, exactly what we wanted.
Again, many thanks for taking the time to porovide such a complete response.
Regards, Kevin
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!