View Single Post
Old 04-30-2023, 02:29 PM   #1
305869
Connoisseur
305869 solves Fermat’s last theorem while doing the crossword.305869 solves Fermat’s last theorem while doing the crossword.305869 solves Fermat’s last theorem while doing the crossword.305869 solves Fermat’s last theorem while doing the crossword.305869 solves Fermat’s last theorem while doing the crossword.305869 solves Fermat’s last theorem while doing the crossword.305869 solves Fermat’s last theorem while doing the crossword.305869 solves Fermat’s last theorem while doing the crossword.305869 solves Fermat’s last theorem while doing the crossword.305869 solves Fermat’s last theorem while doing the crossword.305869 solves Fermat’s last theorem while doing the crossword.
 
Posts: 95
Karma: 28344
Join Date: Mar 2023
Device: Kobo Libra 2, Boox Leaf 7"
How I managed to set up Dropbox cloud sync with KOReader step by step

Maybe it's just me but I found it super complicated to set up Dropbox with KOReader. If you search around you can find these instructions (https://github.com/koreader/koreader...ment-267410178) and they were sufficient to get it set up initially but if you just follow this method after a while your token will expire and it will stop working until you enter a new one manually. I believe there used to be a long-lived token that allowed you to leave it at that but now more work is needed. So I just wanted to explain how I managed to get Dropbox cloud sync for reading statistics working in April of 2023.

1. Made sure I was logged into my Dropbox account. I went to https://www.dropbox.com/developers/apps and created an app. You can give it any name, but the name must be unique.
- Under Choose an API I selected Scoped access
- Under Type of access I selected Full Dropbox.

2. In the app console, I went to permissions and I gave it pretty much all permissions. Screenshot - https://i.imgur.com/sBmMq54.png
- I do not think you need all of these. But while troubleshooting I just enabled all of them in case, and since I only use this dropbox account for reading statistics syncing I felt comfortable doing this.

3. At this point the instructions above tell you to use the Generate token button in the app console settings tab and enter that in KOReader. This will work but only for a few hours, until the token expires. What you need is a refresh token (short, doesn't start with sl.) and your app key and app secret so that KOReader can request a new token every time one is needed to synchronise data.
- The app key and app secret can be found in the settings tab of the app console.

4. Request an authorization code. In the app console, on the settings tab in the OAuth 2 section, I added this URL to the Redirect URI: https://www.dropbox.com/oauth2/autho...s_type=offline (replacing APPKEYHERE with the app key). After adding it I pasted the URL in my browser and pressed "allow" on all the prompts. This will return an authorization code which is needed to obtain a refresh token.
- Note that the URI is being automatically shortened in this post

5. Request a refresh token using curl. Using the terminal I obtained a refresh token with this command:
Code:
curl https://api.dropbox.com/oauth2/token \
-d code=AUTHORIZATION_CODE \
-d grant_type=authorization_code \
-u APP_KEY:APP_SECRET
- Replace AUTHORIZATION_CODE with the code obtained in step 4.
- Replace APP_KEY:APP_SECRET with your key and secret separated by a colon
- In the terminal you get a response with various parameters. The important one is called refresh_token. I copied this code to enter in KOReader.

6. In KOReader, I went to Menu > Tools > Reading Statistics > Settings > Cloud sync. Here I pressed Add Service, and selected Dropbox for type.
- In displayed name, I entered the name of my app that I chose in step 1.
- In the second field (dropbox refresh token or long-lived token) I entered the token obtained in step 5.
- In the third field (<APP_KEY>:<APP_SECRET>) I entered the app key and secret separated by a colon.
- The fourth field I left blank (I think I tried "/" for root first but this didn't work)

Note: This is easier to do in a text editor. You may add any value to these fields, save and then plug your reader in and edit the cloudstorage.lua file found in koreader/settings with any editor so you can paste in the token and app key/secret to avoid mistakes. The file looks like this:
Code:
-- we can read Lua syntax here!
return {
    ["cs_servers"] = {
        [1] = {
            ["address"] = "<app_key>:<app_secret>",
            ["name"] = "<app name>",
            ["password"] = "<refresh token>",
            ["type"] = "dropbox",
            ["url"] = "",
        },
    },
}
After this everything worked for me. I wanted to write it up for my own benefit in case I need to do this again some years later and forget how to and I thought I might as well post it here in case anyone else is pulling their hair out trying to figure out how to get a "short-lived refresh token"

Troubleshooting
I had an issue where Dropbox was working and I could access and download files but reading statistics sync wasn't working. This was fixed by going to Menu > Tools > Reading statistics > Settings > Cloud sync > Edit, then press the Dropbox service name and long press "Long-press to choose current folder" to set the folder. Other issues were fixed by doing a device restart.

Sources
https://github.com/koreader/koreader...ment-267410178
https://github.com/koreader/koreader/issues/9861
https://www.dropboxforum.com/t5/Drop...en/td-p/596739

Last edited by 305869; 04-30-2023 at 05:23 PM. Reason: added sources
305869 is offline   Reply With Quote