cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox 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: 

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

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

Demerson H.
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_key=XXX&oauth_nonce=XXX&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1434773930&oauth_token=XXX&oauth_version=1.0&oauth_signature=XXX 

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

Greg-DB
Dropbox Staff

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/ )

Demerson H.
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.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Demerson H. New member | Level 1
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?