The Community is undergoing a major upgrade. Find out more, ask us questions or share your thoughts here.

Forum Discussion

lonehero's avatar
lonehero
Explorer | Level 4
6 years ago

Can't use the content.dropboxapi

I want to know what i did wrong in this code. Because it is giving error. I am new to this so plz help.

Error: {"error_summary": "path/not_found/..", "error": {".tag": "path", "path": {".tag": "not_found"}}}

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=khvnmek12dw0wv9&redirect_uri=https://c.ap1.visual.force.com/apex/DropboxPage&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.ap1.visual.force.com/apex/DropboxPage';
HttpRequest req = new HttpRequest();
req.setEndpoint(tokenuri);
req.setMethod('POST');
req.setTimeout(60*1000);

Blob headerValue = Blob.valueOf('khvnmek12dw0wv9' + ':' + '<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://content.dropboxapi.com/2/files/download';
HttpRequest r = new HttpRequest();
r.setEndpoint(token);
r.setHeader('Authorization' , 'Bearer ' +accesstoken);
r.setHeader('Dropbox-API-Arg','{\"path\": \"/filepath\"}');
r.setMethod('GET');
r.setTimeout(60000);
Http h1 = new Http();
HttpResponse res1 = h1.send(r);
string resp1 = res1.getBody();
System.debug(' Information :- ' + resp1);
}
}

  • I see that you're trying to call the /2/files/download endpoint, and are getting a "path/not_found" error.

    You can look up what each error for any particular endpoint means in the documentation for that endpoint. For example, for /2/files/download, the "path/not_found" error means: "There is nothing at the given path.". That is to say, there no file or folder at that particular path in the connected account.

    In the code you shared, that's referring to the "/filepath" value you're supplying. I don't know if that's just an example or if that's the actual value you're sending, but you'll need to make sure you're supplying the right value. 

    You can build these values manually, or you can get the paths for files by listing the contents of a folder using /2/files/list_folder[/continue].

    The Content Access Guide and Namespace Guide may also serve as a useful reference here.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    I see that you're trying to call the /2/files/download endpoint, and are getting a "path/not_found" error.

    You can look up what each error for any particular endpoint means in the documentation for that endpoint. For example, for /2/files/download, the "path/not_found" error means: "There is nothing at the given path.". That is to say, there no file or folder at that particular path in the connected account.

    In the code you shared, that's referring to the "/filepath" value you're supplying. I don't know if that's just an example or if that's the actual value you're sending, but you'll need to make sure you're supplying the right value. 

    You can build these values manually, or you can get the paths for files by listing the contents of a folder using /2/files/list_folder[/continue].

    The Content Access Guide and Namespace Guide may also serve as a useful reference here.

About Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,875 PostsLatest Activity: 29 minutes ago
323 Following

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 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!