We Want to Hear From You! What Do You Want to See on the Community? Tell us here!

Forum Discussion

Demerson H.'s avatar
Demerson H.
New member | Level 1
11 years ago

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

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

Replies have been turned off for this discussion

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,036 PostsLatest Activity: 2 days ago
411 Following

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

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!