1

I'm using Asp.net MVC 4 and Dropnet to download a file from my DropBox account. I'm not sure what is wrong with my code but I get a error whenever I run my project,

Received Response [Unauthorized] : Expected to see [OK]. The HTTP response was [{"error": "Request token has not been properly authorized by a user."}].

Here are my codes,

public ActionResult DropDls()
{
    var _client = new DropNetClient("API KEY", "API SECRET");
    DropNet.Models.UserLogin login = _client.GetToken();
    _client.UserLogin = login;
    var url = _client.BuildAuthorizeUrl();
    var accessToken = _client.GetAccessToken();
    var fileBytes = _client.GetFile("/Getting Started.pdf");

    return View();
}

I want only my Dropbox account to be accessed so I need to know how can I give my own USER TOKEN and USER SECRET. I've searched on the web for a solution but couldn't find anything that'll help me.

halfer
  • 19,824
  • 17
  • 99
  • 186
Shihan Khan
  • 2,180
  • 4
  • 34
  • 67

1 Answers1

0

The problem is you are not getting the user to login before trying to access their dropbox account.

This line should not be there _client.UserLogin = login; and after this line var url = _client.BuildAuthorizeUrl(); you will need to redirect the user to that url so they can login, then the dropbox site will redirect them back to your site which is when you make the call _client.GetAccessToken(); then you will have access to the users dropbox account.

dkarzon
  • 7,868
  • 9
  • 48
  • 61
  • Thanks, but I'm really new about this matter so can't figure out what you described. It'd be really helpful if you give me a full demonstration by code. – Shihan Khan Jan 09 '16 at 11:08
  • We don't have an MVC sample but you can have a look at the webforms sample, maybe that will help? https://github.com/DropNet/DropNet.Samples/blob/master/DropNet.Samples.Web/Default.aspx.cs – dkarzon Jan 11 '16 at 00:07
  • The main problem you are having is the flow, there are a few steps to the process to get a user authorized, have a look at the docs of the process here: http://dropnet.github.io/dropnet.html – dkarzon Jan 11 '16 at 00:09