how do we make HTTP requests to dropbox APIs?
We recommend using one of the official SDKs, if possible:
https://www.dropbox.com/developers
Those will handle the work of making the HTTPS calls for you.
Otherwise, you can use your own HTTPS client (whatever that may be for for whatever platform you're using) to connect to the HTTPS endpoints directly:
https://www.dropbox.com/developers/documentation/http/documentation
I prefer to use HTTP endpoints for now.
Is there any code snippets which depicts below way of communicating with dropbox APIs via HTTP(javascript) route
- Authorize and get access token
- call dropbox APIs using access token
The app authorization process is handled via OAuth 2. The documentation for the OAuth 2 page and endpoint can be found here:
https://www.dropbox.com/developers/documentation/http/documentation#oauth2-authorize
There's a blog post here that shows how to implement OAuth 2:
https://blogs.dropbox.com/developers/2013/07/using-oauth-2-0-with-the-core-api/
There's also an OAuth guide here that may be helpful:
https://www.dropbox.com/developers/reference/oauthguide
And here's a simple example of uploading a file (from text) in JavaScript using jQuery:
var data = new TextEncoder("utf-8").encode("Test"); $.ajax({ url: 'https://content.dropboxapi.com/2/files/upload', type: 'post', data: data, processData: false, contentType: 'application/octet-stream', headers: { "Authorization": "Bearer <ACCESS_TOKEN>", "Dropbox-API-Arg": '{"path": "/test_upload.txt","mode": "add","autorename": true,"mute": false}' }, success: function (data) { console.log(data); } })<ACCESS_TOKEN> should be replaced with the OAuth 2 access token.
And here's a simple example of getting the user's account information using jQuery:
jQuery.ajax({ url: 'https://api.dropboxapi.com/2/users/get_current_account', type: 'POST', headers: { "Authorization": "Bearer <ACCESS_TOKEN>" }, success: function (data) { console.log(data); }, error: function (error) { console.log(error); } })<ACCESS_TOKEN> should be replaced with the OAuth 2 access token.