Hi Guys
anyone has already experienced a connection to Dropbox api and a download of a file?
Thanks
Hi Guys
anyone has already experienced a connection to Dropbox api and a download of a file?
Thanks
The dropBox webcast is scheduled for 5/22 and is currently listed on the website. There is a link to signup following. Hope to see everyone there.
https://www.appeon.com/company/events/using-dropbox-rest-api-powerbuilder.html
Giuseppe and Gimmy,
I'm putting together a presentation on this and will be doing an official Appeon webcast, so keep an eye out, it should be soon. It will cover DropBox API - listing files/folders as well as uploading and downloading all file types to/from any shared DropBox folder. It will cover creating a service account for dropbox, generating an OAuth access token, and using that token for DropBox REST API calls. We are currently deciding on a title and date for the webcast, so stay tuned!
Giuseppe,
I spent some time on this over the weekend and got it working. Below is some code to download a file from a shared folder on DropBox. I set up the account as a service account and generated the Access Token on the DropBox site to use for all OAuth REST API requests. The result is a blob in the response body that you can write to a file or db or whatever you want to do with it. This code assumes you know the folder name and file name. I've requested to do a webcast to show how to get a list of files/folders, download a selected file, and upload as well, using OAuth2/REST. Keep an eye out for it if I get approval.
Cheers,
Kevin
Integer li_rc
OAuthClient lo_client
OauthRequest loa_request
ResourceResponse lrr_response
String ls_json, ls_file
Blob lblb_data
CONSTANT String DROPBOX_FOLDER = "/appeondemo"
Long ll_root, ll_item
ls_file = "mypdf.pdf"
ls_json = '{"path":"' + DROPBOX_FOLDER + '/' + ls_file + '"}'
try
lo_client = CREATE OAuthClient
loa_request.Method = "POST"
loa_request.setheader ( "User-Agent", "AppeonDemo" )
loa_request.setheader( "Content-Type","application/octet-stream")
loa_request.setheader( "Dropbox-API-Arg", ls_json)
loa_request.SetAccessToken( "Your Generated Token" )
loa_request.Url = "https://content.dropboxapi.com/2/files/download"
li_rc = lo_Client.RequestResource( loa_request, lrr_response )
If li_rc = 1 Then
lrr_response.GetBody(lblb_data)
//do something with the blob
Else
li_rc = -1
MessageBox("Error", lrr_response.getstatustext())
End If
return li_rc
catch(runtimeerror re)
MessageBox("RunTimeError", re.getmessage())
return -1
finally
IF IsValid(lo_client) THEN
DESTROY lo_client
END IF
end try
thank you Kevin
no issue about connecting, the issue is about downloading...
I haven't tried it yet but did some quick research on it. Looks like as with most REST services, it's going to be a 2 part process. First you will need to connect/authenticate using OAuth to get an access token, then you will use that access token for all REST calls. Check out this link for how to get started. I'd recommend using the App Key and Secret to do this. The link tells you how to generate your app key and secret code and generate an access token. Then you will use that access token to download the file (and anything else you might want to do). You generate the access token once and use it for all API calls.
https://www.dropbox.com/developers/support
Once you generate the app key, secret and access token, use the OAuthClient object to make all API calls with the access token. Below are 2 links for retrieving a list of files/folders and for downloading a file by name.
Note: updated on 4/15/19. I replaced some text above regarding the access token. Normally using OAuth, you have to request an access token using your client id and client secret in your first call, then use the access token for your session. DropBox does it a little different. You generate the access token once when you setup your service account, so you don't have to make a separate call to get it.
https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder
https://www.dropbox.com/developers/documentation/http/documentation#files-download
They return JSON, so you can probably setup a nice DW showing the file list, then cal the get when they select one. Looks like fun!
Cheers,
Kevin
In the meantime, with your help we were able to create 2 exe uploading and downloading other powerbuilder compiled exe and pbd from dropbox
Thanks again!