cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Re: URL Unauthorized access error while accessing files from dropbox?

URL Unauthorized access error while accessing files from dropbox?

sobharaj m.
New member | Level 1

we are accessing having a problem in URL we have a file named xyx (1).jpg while passing this to server we are getting response as Unauthorized Access. May I Know how to pass this request to Server?

Here am using DropBox API for Winrt C#.

39 Replies 39

sobharaj m.
New member | Level 1

Yes I have trouble in thumbnails.

Steve M.
Dropbox Staff

Can you share your latest code for retrieving thumbnails?

sobharaj m.
New member | Level 1

Avatar

file = await tempCatcheFolder.CreateFileAsync(fileName, CreationCollisionOption.OpenIfExists);
DropboxApi api = new DropboxApi(DropBoxAccessToken, DropBoxAccessTokenSecret);
string url = DriveUtilities.GenerateSignature(new Uri(string.Format(AppConstants.DropBoxGetThumbnail, item.serverFileId), UriKind.RelativeOrAbsolute),
    "GET", DropBoxAccessToken, DropBoxAccessTokenSecret);
Stream fileStream = await FileHelper.getFileInputStream(url);
if (fileStream != null)
{
    try
    {
        if (fileStream.Length > 0)
        await FileSaveToStorage(fileStream, file);
        handler(fileStream);
    }
    catch (Exception ex)
    {
    }
}
else
{
    string path = WebUtility.UrlEncode(item.serverFileId);
    url = DriveUtilities.GenerateSignature(new Uri(string.Format(AppConstants.DropBoxGetThumbnail, path), UriKind.RelativeOrAbsolute),
        "GET", DropBoxAccessToken, DropBoxAccessTokenSecret);
    fileStream = await FileHelper.getFileInputStream(url);
    if (fileStream != null)
    {
        try
        {
            if (fileStream.Length > 0)
            await FileSaveToStorage(fileStream, file);
            handler(fileStream);
        }
        catch (Exception ex)
        {
        }
    }

Steve M.
Dropbox Staff

It looks like this code tries two different calls, one in which the file path is manually URL encoded and one in which it isn't. Why is that?

Maybe you can print out the value of "url" right before you make the call and share that, but please remember to replace the OAuth signature with Xs so you don't share your credentials.

sobharaj m.
New member | Level 1

in case of If block

https://api-content.dropbox.com/1/thumbnails/auto/images (87).jpeg?oauth_consumer_key=xs&oauth_token=xs&oauth_nonce=1015776&oauth_timestamp=1427259241&oauth_signature_method=PLAINTEXT&oauth_version=1&oauth_signature=xs

in case of else block.

https://api-content.dropbox.com/1/thumbnails/auto%2Fimages+(87).jpeg?oauth_consumer_key=xs&oauth_token=xs&oauth_nonce=724397&oauth_timestamp=1427259387&oauth_signature_method=PLAINTEXT&oauth_version=1&oauth_signature=xs

Steve M.
Dropbox Staff

Everything looks roughly right (in the first URL), so I would assume that one of the parameters is wrong (oauth_consumer_key, oauth_token, or oauth_signature).

Compare those values to the URL you use for /media (the one that's working) to make sure everything's the same.

sobharaj m.
New member | Level 1

Okay let me see.

sobharaj m.
New member | Level 1

There is no difference between oauthconsumerkey, oauthtoken, or oauthsignature everything is same for both urls.

Steve M.
Dropbox Staff

I'm not sure what's going wrong in your code, so I thought I'd instead provide some working code I wrote for you. The method below returns the full URI to download a thumbnail from Dropbox.

Note that I'm not using OAuthBase.GenerateSignature. That method returns a URL-encoded version of the signature, which I found hard to work with. Because we're using PLAINTEXT signing, it's very easy to construct the signature yourself. It's just the app secret, then an ampersand (&), and then the token secret.

static Uri GetThumbnailUri(string path, string appKey, string appSecret, string token, string tokenSecret) {
    var oauthBase = new OAuth.OAuthBase();

    var ub = new UriBuilder(@"https://api-content.dropbox.com/1/thumbnails/auto/" + path.TrimStart('/'));

    // get an empty HttpValueCollection
    var parameters = HttpUtility.ParseQueryString(string.Empty);

    // add all the OAuth parameters
    parameters["oauth_consumer_key"] = appKey;
    parameters["oauth_token"] = token;
    parameters["oauth_nonce"] = oauthBase.GenerateNonce();
    parameters["oauth_timestamp"] = oauthBase.GenerateTimeStamp();
    parameters["oauth_version"] = "1.0";
    parameters["oauth_signature_method"] = "PLAINTEXT";
    parameters["oauth_signature"] = appSecret + "&" + tokenSecret;

    // set the query string for the URL
    ub.Query = parameters.ToString();

    return ub.Uri;
}

sobharaj m.
New member | Level 1

Thank you for your Response.

Need more support?