Hi Dropbox Community,
I've created a Google Apps Script to automatically send copies of modified Excel files as CSV files to my Dropbox. The script uses a Dropbox App Folder (created in the App Console) and works by using a Dropbox access token. The App is simple and doesn't require Redirect URIs, Webhook URIs, etc.
My script (snippet below) worked perfectly for several hours, relying solely on the access token:
function onEdit(e) {
// Configuration
const ACCESS_TOKEN = 'DropBox_Access_Token';
const DROPBOX_FOLDER_PATH = 'Folder_Path';
const FILE_NAME = 'data.csv'; // Name of the CSV file in Dropbox
// ... (rest of the script)
}
However, after some time, it stopped working with this error:
Error uploading file to Dropbox: Exception: Request failed for https://content.dropboxapi.com returned code 401. Truncated server response: {"error_summary": "expired_access_token/", "error": {".tag": "expired_access_token"}} (use muteHttpExceptions option to examine full response)
This clearly indicates the access token has expired. The script's purpose is to run automatically without manual intervention.
My question is: how to get long-lived access token and how can I modify my Apps Script to use a long-lived access token or a refresh token mechanism to prevent this token expiration issue?
Any guidance or examples would be greatly appreciated.
Thanks in advance for your help!