Forum Discussion

Kevin B.36's avatar
Kevin B.36
Collaborator | Level 9
2 months ago
Solved

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 tha...
  • Здравко's avatar
    Здравко
    24 days ago

    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!

About Dropbox API Support & Feedback

Node avatar for 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!