cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
Update: Find information on Dropbox support during COVID-19 here
Close
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

REST C# 401/403 Error. Problem Retrieving share link

New member | Level 1
New member | Level 1

Hi,
I am trying to use REST to retrieve a file sharing link but I am receiving either error 401 or 403. The error I receive varies according to the tests that I try to run lol.

I have the following method:

static string HttpPost(string url, string[] paramName, string[] paramVal)
    {
        var req = WebRequest.Create(new Uri(url))
                             as HttpWebRequest;
        req.Method = "POST";
        req.ContentType = "application/x-www-form-urlencoded";
        req.Accept = "*/*";

        // Build a string with all the params, properly encoded.
        // We assume that the arrays paramName and paramVal are
        // of equal length:
        var paramz = new StringBuilder();

        for (int i = 0; i < paramName.Length; i++)
        {
            paramz.Append(paramName[i]);
            paramz.Append("=");
            paramz.Append(HttpUtility.UrlEncode(paramVal[i]));
            paramz.Append("&");
        }

        // Encode the parameters as form data:
        byte[] formData =
            UTF8Encoding.UTF8.GetBytes(paramz.ToString());
        req.ContentLength = formData.Length;

        // Send the request:
        using (var post = req.GetRequestStream())
        {
            post.Write(formData, 0, formData.Length);
        }

        // Pick up the response:
        string result = null;
        using (var resp = req.GetResponse()
                                      as HttpWebResponse)
        {
            var reader =
                new StreamReader(resp.GetResponseStream());
            result = reader.ReadToEnd();
        }

        return result;
    }

I pass as parameter the following:
url: https://api.dropbox.com/1/shares/auto/path
parameters
values

In my first try, I have tried passing as parameters as parameter the following:
oauth_consumer_key, oauth_nonce, oauth_signature_method, oauth_timestamp, oauth_token, oauth_version, oauth_signature

As a result, I have received Error 403 Forbidden. so I assumed I was receiving this error because of authentication which is funny because I am passing through the parameters, so then I did the following:

included those parameters after the url just like the example below:

https://api-content.dropbox.com/1/shares/auto/PATH?oauth_consumer_keyXX&oauth_nonceXX&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1434773930&oauth_tokenXX&oauth_version=1.0&oauth_signatureXX 

As a result I have received error 401 Unauthorized.

I am obtaining file URI through SharpBox, using the following:
var uri = dropBoxStorage.GetFileSystemObjectUrl(file.Name, folder);
Would anyone know why I am not able to retrieve that sharing link?

2 Replies 2
Highlighted

Re: REST C# 401/403 Error. Problem Retrieving share link

Dropboxer
Dropboxer

You're using OAuth 1 with HMAC-SHA1 signing, which is prone to issues like this. We highly recommend using PLAINTEXT signing instead, as it's much easier to implement and debug:

https://blogs.dropbox.com/developers/2012/07/using-oauth-1-0-with-the-plaintext-signature-method/

Try that and let us know if that doesn't help.

(Or, you can use OAuth 2: https://blogs.dropbox.com/developers/2013/07/using-oauth-2-0-with-the-core-api/ )

Highlighted

Re: REST C# 401/403 Error. Problem Retrieving share link

New member | Level 1
New member | Level 1

I ended up using another API using Oauth2 and it all worked. SharpBox is not updated for long time so I preferred to use a different one.

Thanks for your reply Greg.

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?