You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
sarfaraz_k
2 years agoNew member | Level 2
Salesforce - Dropbox API Connection
Please help me regarding integration between dropbox and salesforce ,
I want to get user details from dropbox and display it in salesforce.
Another requirement is, upload files from salesforce and upload it in dropbox . and get the files or images from dropbox and display it in salesforce....
I have access token ,api key, api secret all things , but I don't know how pass request and how to get response as user details.
In below Code ... in system debug I m getting
{ access_token":"REDACTED", "token_type": "bearer", "uid": "328256643"}
But in system.debug of Account Information, I m getting following error- Account Information ::
{"error": "OAuth 2 \"Authorization\" header is not well-formed."}
Below is Apex Class:
public class DropboxController { //Fetched from URL String code ; String accesstoken; public DropboxController() { code = ApexPages.currentPage().getParameters().get('code') ; //Get the access token once we have code if(code != '' && code != null) { AccessToken() ; } } public PageReference DropAuth() { //Authenticating PageReference pg = new PageReference('https://www.dropbox.com/1/oauth2/authorize?response_type=code&client_id=nw7mfi19tfaxak8&redirect_uri=https://c.ap2.visual.force.com/apex/Dropbox&state=Mytesting') ; return pg ; } public void AccessToken() { //Getting access token from dropbox String tokenuri = 'https://api.dropbox.com/1/oauth2/token?grant_type=authorization_code&code='+code+'&redirect_uri=https://c.ap2.visual.force.com/apex/Dropbox'; HttpRequest req = new HttpRequest(); req.setEndpoint(tokenuri); req.setMethod('POST'); req.setTimeout(60*1000); Blob headerValue = Blob.valueOf('nw7mfi19tfaxak8' + ':' + 'REDACTED'); String authorizationHeader = 'BASIC ' + EncodingUtil.base64Encode(headerValue); req.setHeader('Authorization', authorizationHeader); Http h = new Http(); String resp; HttpResponse res = h.send(req); resp = res.getBody(); JSONParser parser = JSON.createParser(resp); while (parser.nextToken() != null) { if ((parser.getCurrentToken() == JSONToken.FIELD_NAME)){ String fieldName = parser.getText(); parser.nextToken(); if(fieldName == 'access_token') { accesstoken = parser.getText(); } } } system.debug('accessToken==>'+accessToken ); System.debug(' You can parse the response to get the access token ::: ' + resp); string token = 'https://api.dropbox.com/1/account/info'; HttpRequest r = new HttpRequest(); r.setEndpoint(token); r.setHeader('Authorization','Bearer' +accesstoken); r.setMethod('GET'); r.setTimeout(60000); Http h1 = new Http(); HttpResponse res1 = h1.send(r); string resp1 = res1.getBody(); System.debug(' Account Information :: ' + resp1); } }
As I am new to integration any help will be grateful...
Thanks
sarfaraz_k wrote:...
But in system.debug of Account Information, I m getting following error- Account Information ::
{"error": "OAuth 2 \"Authorization\" header is not well-formed."}
...
... string token = 'https://api.dropbox.com/1/account/info'; HttpRequest r = new HttpRequest(); r.setEndpoint(token); r.setHeader('Authorization','Bearer' +accesstoken); r.setMethod('GET');
......
Hi sarfaraz_k,
Take in mind that 'Authorization' header' value should contain its type and the value. These are 2 different things that have to stay different (i.e. with separator between). As far as can be seen you have stick them together. That's why the format doesn't go well. 😉 To avoid such mistakes use some of the official SDKs or prototype your calls using API explorer.
By the way you're using unsupported call; better use 2/users/get_current_account, for instance.
Good luck.
- ЗдравкоLegendary | Level 20
sarfaraz_k wrote:...
But in system.debug of Account Information, I m getting following error- Account Information ::
{"error": "OAuth 2 \"Authorization\" header is not well-formed."}
...
... string token = 'https://api.dropbox.com/1/account/info'; HttpRequest r = new HttpRequest(); r.setEndpoint(token); r.setHeader('Authorization','Bearer' +accesstoken); r.setMethod('GET');
......
Hi sarfaraz_k,
Take in mind that 'Authorization' header' value should contain its type and the value. These are 2 different things that have to stay different (i.e. with separator between). As far as can be seen you have stick them together. That's why the format doesn't go well. 😉 To avoid such mistakes use some of the official SDKs or prototype your calls using API explorer.
By the way you're using unsupported call; better use 2/users/get_current_account, for instance.
Good luck.
- DB-DesDropbox Engineer
Здравко is correct. I would suggest following his guidance.
By the way, you shared your access token, I went ahead and redacted that information.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,889 PostsLatest Activity: 45 minutes agoIf 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 or Facebook.
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!