Your workflow is unique 👨💻 - tell us how you use Dropbox here.
Forum Discussion
lucasj
2 years agoExplorer | Level 3
Powershell Oauth2 Refresh Token
Hey all! Thanks in advanced. I am trying to write a powershell script to get an offline refresh token so I can do unattended uploads. The problem is that I have to authenticate for an author...
- 2 years ago
I'm not sure what you mean when you say you are "not getting any type of response from the curl command". For reference, if you need to debug something with curl, you can use the "-v" flag to enable verbose mode.
In any case, I haven't tested your new code, but the parameters look right. I also don't see where you retrieve the access token from the new /oauth2/token call, but assuming you do either manually or in code not shown, it seems right. Does it work for you when you run it?
lucasj
2 years agoExplorer | Level 3
So I used this code to upload files. I tried using the refresh token and it doesn't work...
$refresh_token = "hssEaww....REFRESHTOKENWENTHERE"
$headers = @{
Authorization = "Bearer $refresh_token"
"Content-Type" = "application/octet-stream"
}
# Read the file as a byte array and upload it to Dropbox
$file_bytes = [System.IO.File]::ReadAllBytes($file_path)
$outputFile = Split-Path "C:\FILEHERE.TXT" -leaf
$TargetFilePath = "/$outputFile"
$arg = '{ "path": "' + $TargetFilePath + '", "mode": "add", "autorename": true, "mute": false }'
$authorization = "Bearer " + $refresh_token
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", $authorization)
$headers.Add("Dropbox-API-Arg", $arg)
$headers.Add("Content-Type", 'application/octet-stream')
$response = Invoke-RestMethod -Uri https://content.dropboxapi.com/2/files/upload -Method Post -InFile $SourceFilePath -Headers $headers
Greg-DB
Dropbox Community Moderator
2 years agoAccess tokens and refresh tokens are different objects and are not interchangeable, so you can't use a refresh token as an access token like that. Instead, whenever you need a new short-lived access token you should call /oauth2/token with grant_type=refresh_token and refresh_token set to the refresh token, like in step 5 of this example. That call will return a new short-lived access token which you can then use to make further API calls, such as /2/files/upload.
About Discuss Dropbox Developer & API
Make connections with 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!