Need to see if your shared folder is taking up space on your dropbox 👨‍💻? Find out how to check here.

Forum Discussion

sobharaj m.'s avatar
sobharaj m.
New member | Level 1
11 years ago

URL Unauthorized access error while accessing files from dropbox?

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

Replies have been turned off for this discussion
  • Can you share your latest code for retrieving thumbnails?

  • sobharaj m.'s avatar
    sobharaj m.
    New member | Level 1
    11 years ago

    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)
            {
            }
        }
    
  • 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.'s avatar
    sobharaj m.
    New member | Level 1
    11 years ago

    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
    
  • 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.'s avatar
    sobharaj m.
    New member | Level 1
    11 years ago

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

  • 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;
    }
    

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

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, Facebook or Instagram.

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!