Announcements
Known issues updated. Learn more

Can't use the content.dropboxapi

Explorer | Level 4

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...');
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=http...';
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);
}
}

1 Accepted solution

Accepted Solutions
Highlighted

Re: Can't use the content.dropboxapi

Dropboxer

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.

Reply
Loading...
2 Replies
Highlighted

Re: Can't use the content.dropboxapi

Dropboxer

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.

Reply
Loading...

Re: Can't use the content.dropboxapi

Explorer | Level 4

Thanks my issue got solved.

Reply
Loading...
API Support

Have a question? Our Dropbox Community is here to help you find an answer!
You won’t have to wait too long for a reply, but why not learn more about the Community while you’re here.

Not the right discussion for you? Find out what else our Community has to say about API Support.

Or, search our Help Center for even more.